How to get provider access token in Firebase functions?

耗尽温柔 提交于 2019-12-11 04:34:26

问题


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: {} }

回答1:


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.



来源:https://stackoverflow.com/questions/45858683/how-to-get-provider-access-token-in-firebase-functions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!