Reputation:
I'm planning to write Firebase function on Authentication user creation. My goal is to get the long live access token for the Facebook user page's.
To do that I need user access token in Firebase functions. Tried below..,
exports.saveLongLiveToken = functions.auth.user().onCreate(event => {
console.log(event.providerData)
})
I though providerData will have the information about the Facebook credentials, but not instead I got only undefined.
Note: In the event, I got below
{ data:
{ displayName: 'Rob',
email: 'xxx@xyz.com',
metadata:
{ createdAt: 2017-08-23T18:58:34.000Z,
lastSignedInAt: 2017-08-23T18:58:34.000Z },
photoURL: 'http...',
providerData: [ [Object] ],
uid: 'xfff...' },
eventId: 'xxx',
eventType: 'providers/firebase.auth/eventTypes/user.create',
notSupported: {},
resource: 'projects/fiobot-4fa94',
timestamp: '2017-08-23T18:58:34.571Z',
params: {} }
Upvotes: 1
Views: 1706
Reputation: 30868
If you are signing in with Firebase Auth signInWithPopup/Redirect, you will only get the access token after sign-in. Firebase Auth does not store it for you (neither does it store the Facebook refresh token). You will need to save it in the Database where only the specified user can access it and the Admin SDK via Firebase Functions can allow you access it. If you think Firebase Auth should manage OAuth tokens for providers, please file a request via Firebase Support channels.
If this is essential for your app functionality, you can use the Facebook API to sign in the user and get a Facebook access token and sign in with firebase.auth().signInWithCredential(firebase.auth.FacebookAuthProvider.credential(fbAccessToken))
Facebook client API can manage the OAuth token for you. You can also use a backend OAuth node.js library to refresh Facebook tokens via the Firebase Functions whenever you need one. You would need to get the Facebook refresh token though.
Upvotes: 2