问题
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:
- Implement a paypal OAuth code flow. You can use third party libraries for that.
- 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.
- 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