Firebase Authentication With Custom Backend
I plan to use Firebase for authentication for my iOS app. But I want to use custom backend for rest of the REST APIs. How can I add authorization for users authenticated with Firebase in my custom backend ? Can we use both custom backend and firebase authentication? How do I maintain the session using both Firebase and custom backend?
Answer
You can verify the token on your backend server with the firebase Admin SDK.
So on the app you get a firebase access token and send this to your server. On IOS you do:
FIRUser *currentUser = [FIRAuth auth].currentUser;
[currentUser getIDTokenForcingRefresh:YES
completion:^(NSString *_Nullable idToken,
NSError *_Nullable error) {
if (error) {
// Handle error
return;
}
// Send token to your backend via HTTPS
// ...
}];
More Info here: https://firebase.google.com/docs/auth/admin/verify-id-tokens#retrieve_id_tokens_on_clients
On the server you do:
admin.auth().verifyIdToken(idToken)
.then(function(decodedToken) {
var uid = decodedToken.uid;
// ...
}).catch(function(error) {
// Handle error
});
As you can see you even get the "uid" of the user. More Infos here: https://firebase.google.com/docs/auth/admin/verify-id-tokens
Related Questions
- → Function Undefined in Axios promise
- → What are the pluses/minuses of different ways to configure GPIOs on the Beaglebone Black?
- → Click to navigate on mobile devices
- → Playing Video - Server is not correctly configured - 12939
- → How to allow api access to android or ios app only(laravel)?
- → Axios array map callback
- → Access the Camera and CameraRoll on Android using React Native?
- → Update React [Native] View on Day Change
- → Shopify iOS SDK - issue converting BuyProductVariant to BuyProduct
- → BigCommerce and shopify API
- → Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView`
- → React Native - Differences between Android and IOS
- → What is the difference between React Native and React?