Closed nandorojo closed 2 years ago
There is no expo plugin here, but we're open to one. In general though if you are using expo, I'd definitely use their library. It's not like the firebase stuff where the Expo versions work but just don't do the native integration (thus making a case for expo plugins in RNFB, and we do have them there)
Sad to say this though, as I'm certain if I'm you, I no longer show up here anymore and I have to make sure web auth works here myself :laughing: - it's the truth though. expo apple plugin should do you right
Makes sense! In that case, I think I'm going to add web support to expo-apple-authentication
😈. I'll be using it with RNFB.
The one issue: it doesn't seem like Expo's sign in returns a nonce
.
Apologies for my ignorance on what the nonce does, but is that required? This is what I see on the docs:
Instead, Expo returns this:
Does this response from expo's signIn
function look sufficient for usage with RNFB?
Expo does allow a nonce
to be provided as an argument to signIn
, but it isn't part of the response, the way it is with your lib:
Thanks for the help here, I really appreciate the fast responses.
I assume I can just pass a nonce to expo, and then the same one to RNFB in the next step, right? And do I just generate a random uuid() on the fly there?
I believe "state" is the same thing, @brentvatne would know for absolute certain but I'm 99.99% sure on it based on the text associated with that string being roughly equivalent to all the nonce-related documentation. May do to post a quick clarifying PR to that doc that explicitly uses the word "nonce"
nonce is just an anti-replay attack protection, "Number Only Used Once". I think you want to use the string that comes back from expo signin in state as the nonce for the firebase auth token.
There are a few strategies to use to generate a nonce, I would definitely follow whatever the Expo docs say htere
that looks right. thanks!
@nandorojo can you please share how you went ahead with generating the nonce?
I don't really remember but I'll check when I'm at my computer. You mean for Web?
Thanks for the quick response! Really appreciate that.
I didn't mean it for any specific platform earlier, though I want to use this on iOS only. What I meant was since expo-apple-authentication
doesn't provide any nonce
, how are you generating the nonce to be supplied to Firebase AuthProvider
after sign-in? Also, are you supplying the same nonce to Expo's signIn
function?
Here's what I did on iOS:
import * as AppleAuthentication from 'expo-apple-authentication'
import auth from '@react-native-firebase/auth'
const signInWithApple = async () => {
try {
const { state, identityToken } = await AppleAuthentication.signInAsync({
requestedScopes: [
AppleAuthentication.AppleAuthenticationScope.FULL_NAME,
AppleAuthentication.AppleAuthenticationScope.EMAIL,
],
})
const credential = auth.AppleAuthProvider.credential(
identityToken,
state || undefined
)
return auth().signInWithCredential(credential)
// signed in
} catch (e: any) {
if (e.code === 'ERR_CANCELED') {
// handle that the user canceled the sign-in flow
} else {
// handle other errors
}
}
}
Awesome @nandorojo! I now understand what @mikehardy meant when he said:
I believe "state" is the same thing
Thank you so much Fernando for your help :D
@nandorojo would you have time to explain how the signInWithApple
above integrates with React Native FireBase using Expo?
..big fan of the Solito starter repo 👍
Did you try out the code? Notice that it signs in with Apple, and then uses the credential & passes it to RN Firebase.
@nandorojo sorry I got confused with package names and read it wrong, yes makes sense thank you!
If anyone wants to use this library with managed expo you can do the following:
edit app.json and set "expo.ios.entitlements" to the following value:
{
"entitlements": {
"com.apple.developer.applesignin": ["Default"],
}
}
Thank you @maxencehenneron . I would use expo package, but it does not offer apple sign in on Android.
Thank you @maxencehenneron . I would use expo package, but it does not offer apple sign in on Android.
Yes, same. Thanks why I am using this package.
If anyone wants to use this library with managed expo you can do the following:
edit app.json and set "expo.ios.entitlements" to the following value:
{ "entitlements": { "com.apple.developer.applesignin": ["Default"], } }
This fixed my problem!
@Arjan-Zuidema I think "expo.ios.entitlements" is for IOS build environment? If I need to build it for android what should I do? Best regards.
I didn;t had any errors when using Android, so I can't help you, sorry 🙂
@Arjan-Zuidema Could you share me the example of app.json for android-Applesignin setup?
There is nothing related to Apple Sign-in in my app.json for Android
It also works for me only on iOS.
When I call the signInAsync
method on Android I see the following error:
const { authorizationCode } = await AppleAuthentication.signInAsync({
requestedScopes: [
AppleAuthentication.AppleAuthenticationScope.FULL_NAME,
AppleAuthentication.AppleAuthenticationScope.EMAIL,
],
});
return authorizationCode;
And the error I see on Android is this one:
ERROR [Error: The method or property expo-apple-authentication.signInAsync is not available on android, are you sure you've linked all the native dependencies properly?]
It works on iOS. @Arjan-Zuidema can you share a snippet that works for you on Android?
Is there a config plugin for this, similar to
expo-authentication-apple
? Or should I just use that library? Trying to figure out what is best to work with RNFB. @mikehardy any idea? thank you!It seems like Expo's is effectively just modifying the Info Plist: https://github.com/expo/expo/blob/sdk-43/packages/expo-apple-authentication/plugin/src/withAppleAuthIOS.ts
So maybe I can just do that.
The other difference seems to be that Expo uses a native button, rather than a pure JS one (which wouldn't work on web)