How should I create a new Federated Identity Provider for Firebase Authentication

前提是你 提交于 2019-12-10 12:18:58

问题


I would like to integrate PayPal signin into an android app so to authenticate the client to the Firebase Database. I've managed to create a custom funtion on the node.js server that creates tokens from the provided uid, in order to use "signin withcustomtoken" function in the client application. Should I send the uid to the nodejs server through https in order to get the token? Is there a better way?


回答1:


Don't create an HTTP endpoint that accepts a uid and returns a custom token. This is a huge security vulnerability as any attacker would be able to impersonate any user knowing their uid. What you need to do is the following:

  1. Implement a paypal OAuth code flow. You can use third party libraries for that.
  2. When you get the paypal OAuth authorization code, you send it to your backend, you use the paypal client ID and secret to exchange for a paypal refresh token and access token. You can then get the user info associated with that paypal user including their paypal uid. You would then mint a Firebase custom token using the Firebase Admin SDKs and return it to the client.
  3. On the client you would signInWithCustomToken to complete sign in with that custom token.

In this case you are exposing an HTTP endpoint that takes an authorization code and returns a Firebase custom token.

This is the basic idea (details excluded). Of course you still have to ensure the flow starts and ends on the same device by passing some state and then check that you get it back in the end. You also have to ensure the auth code is returned to the correct app using something like app links, etc. Firebase Dynamic Links can be helpful there.



来源:https://stackoverflow.com/questions/47415787/how-should-i-create-a-new-federated-identity-provider-for-firebase-authenticatio

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