-
Notifications
You must be signed in to change notification settings - Fork 224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Authenticating via Firebase on Android #149
Comments
I'm not sure anyone has tried it, you might be first! Unfortunately that means you are the current leading edge of knowledge in the area 😅 |
This is definitely one of those issues in between the two libraries but might be best in the react-native-firebase library, It is supposed to work thought now that I look more deeply: @dburdan - did you integrate with react-native-firebase for Android Apple auth or are you using something else? If so, do you have it working and it's just an API usage issue here? If not, we'll keep digging @Sebastian-Neubert the best I can suggest is going into node_modules around the line that I linked there and logging out all the inputs and outputs to the underlying API call to start tracing the data and comparing it vs the assumptions in the code to see where things go off the rails |
@mikehardy My implementation was fully bespoke; I'm unfamiliar with Firebase Auth or the RN library, but I'm happy to lend a hand here. @Sebastian-Neubert Did you pass your nonce value through to Firebase? If I'm not mistaken, I believe Firebase needs just the id_token and nonce. |
@dburdan In the iOS implementation I indeed passed the id_token and nonce to Firebase but on Android I don't get a value named nonce from the library. The only available values in the response are: |
Have you tried generating the nonce before hand and providing it to both libraries as seen in the Android example? The nonce can be any unique, random set of characters, like a UUID. I will take a deeper look at the return values on Android to make sure they match iOS. |
No, I haven't generated the nonce before hand. The iOS-part of the library does that somehow automatically and provides it for me. |
Hi, I was stuck with the same problem. I got it working like this: const getRandomString = length => {
let randomChars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
let result = ''
for (let i = 0; i < length; i++) {
result += randomChars.charAt(Math.floor(Math.random() * randomChars.length))
}
return result
}
export const appleLogin = async () => {
return Platform.select({
ios: iosAppleLogin(),
android: androidAppleLogin(),
})
}
const iosAppleLogin = async () => {
const appleAuthRequestResponse = await appleAuth.performRequest({
requestedOperation: appleAuth.Operation.LOGIN,
requestedScopes: [appleAuth.Scope.EMAIL, appleAuth.Scope.FULL_NAME],
})
if (!appleAuthRequestResponse.identityToken) {
throw 'Apple Sign-In failed - no identify token returned'
}
const { identityToken, nonce } = appleAuthRequestResponse
const appleCredential = auth.AppleAuthProvider.credential(
identityToken,
nonce,
)
return auth().signInWithCredential(appleCredential)
}
const androidAppleLogin = async () => {
// Generate secure, random values for state and nonce
const rawNonce = getRandomString(20)
const state = getRandomString(20)
// Configure the request
appleAuthAndroid.configure({
clientId: 'THE SAME SERVICE ID AS APPLE DEV AND FIREBASE CONSOLE',
redirectUri: 'THIS IS THE SAME AS APPLE DEV CONSOLE',
responseType: appleAuthAndroid.ResponseType.ALL,
scope: appleAuthAndroid.Scope.ALL,
nonce: rawNonce,
state,
})
const response = await appleAuthAndroid.signIn()
if (response.state === state) {
const credentials = auth.AppleAuthProvider.credential(
response.id_token,
rawNonce, // Passing the rawNonce here do the trick.
)
return auth().signInWithCredential(credentials)
}
} The idea is to generate the nonce ourselves and just passing it to Firebase to let it check if what give Apple is the same as what we give in the nonce. |
Appears this might a documentation / example issue then, or we could decide to handle it internally for Android. I'd take PRs for either for iOS we do handle it internally (with the ability to disable) - here's a PR that added the ability to disable nonce for ios if people are interested in seeing all the places nonce is touched #52 |
I submitted a PR (#153) that adds support for automatic nonce generation on Android. While I ran it through various tests, I don't personally use this feature, so additional checks would be appreciated. Hopefully this provides more parity with the iOS half of the library. |
Hi, i'm facing this issue too. I try to go by documentation and by @ghivert answer but without success. Is there someone with working solution for Firebase? 🙏 web login is open, user fill login info and function I know this is not stackoverflow but... there is my code and Firebase config: import { appleAuthAndroid } from '@invertase/react-native-apple-authentication'
import uuid from 'uuid'
const rawNonce = uuid()
const state = uuid()
appleAuthAndroid.configure({
clientId: 'APPLE_CLIENT_ID',
redirectUri: 'REDIRECT_CALLBACK',
responseType: appleAuthAndroid.ResponseType.ALL,
scope: appleAuthAndroid.Scope.ALL,
nonce: rawNonce,
state,
})
const response = await appleAuthAndroid.signIn()
if (response.state === state && response.id_token) {
const providerData = auth.AppleAuthProvider.credential(
response.id_token,
rawNonce // or response.code -> without success
)
await auth().signInWithCredential(providerData)
} else {
throw new Error('Apple sign-in error')
} Packages: |
Hi @alesmraz, It looks like an issue with Firebase. Are you sure you provide the Apple Service ID in Firebase Dashboard ? You can find it on Apple Developers Dashboard under service section. I had this error at first because I was providing bundle app ID and not service ID. Edit : are your OAuth settings completed too ? |
It still does not work for me as well. I have everything set up correctly (I guess), even the OAuth settings, but I always get the error:
|
|
@mikehardy But why is it not supported in my case? What could be the reasons? |
@Sebastian-Neubert it is, that line runs and executes correctly. Note it is on a different imported type |
@mikehardy You are right, it is supported. But the login with Firebase does still not work. Even the solution from @ghivert does not work for me. |
@ghivert Thanks for advice! I double checked configuration in Firebase and Apple Developers and it's same. I also try hash (SHA256) nonce before go to apple service server but without success. Also function isSupported return true. OAuth setting is completed. We already has Apple auth on web (not React native) connected to same firebase without any issues. I assume that is work same (please correct me if its wrong) on web and on non-apple devices? |
Hum, that’s weird… It should work in the same for web and Android because it uses OAuth to authenticate in a web-browser. In Android, it’s just a matter of handling the redirect URL correctly. The error |
@alesmraz any luck? I'm stuck on the same workflow. |
@alesmraz |
Also having the same issue with Android Apple Sign in. (Works with iOS I get the UID from Firebase just fine) const response = await appleAuthAndroid.signIn();
const { id_token } = response;
const androidCredential = firebase.auth.OAuthProvider.credential(
id_token,
rawNonce,
);
const userCredential = await firebase
.auth()
.signInWithCredential(androidCredential); Looks like I get everything I need with
but the userCredential doesn't return a UID from Firebase like it does Apple, it doesn't return anything nor does it register the user in the Firebase console. Followed this https://github.com/invertase/react-native-apple-authentication/blob/master/example/app.android.js#L61 This seems like an issue with |
I think you have to decode the idtoken - see #160 |
@mikehardy decode the id_token how? That comment in the issue you shared does not mention that. |
Did you try with |
I was stuck with the same problem. |
For me adding correct Services ID to firebase apple auth settings solved the issue, it is optional for iOS so I had it empty. I am using |
I am implementing sign in with Apple. I can successfully see the Apple login page. I key in the correct credentials. It should be able to sign in/sign up to the firebase based on the returned value from Apple. However I am getting this error What I have done: In Firebase
In developer.apple.com
My React Native source code
|
It looks like you're using an old version of Firebase. You should try with the latest up to date package |
@ghivert Hi, I may not feasible to perform the upgrade as it will cause breaking changes. Currently my version is |
I’m using |
Happy to take PRs to resolve issues / extend functionality but as current maintainer the library currently handles my use cases, which means I do not have an interest in volunteering unpaid labor myself for use cases I don't need. Happy to take those PRs and merge them though if anyone paying attention to this issue is motivated to develop them. In the meantime closing this as stale |
Hello there,
I have successfully set up the Firebase login process on iOS but is there a way to do this on Android as well? I tried passing the id_token and the code to
AppleAuthProvider.credential()
but that resulted in this error:Am I missing something or is it actually not possible at the moment?
Regards
The text was updated successfully, but these errors were encountered: