Shi*_*a K 5 single-sign-on react-native expo react-native-firebase
我正在开发一个需要通过 FireBase 使用 Apple 和 Google 登录的应用程序。在开发模式下,signIn 与两者都可以正常工作。但在 TestFlight 中部署后,我无法再使用它们登录。
还有 SignIn with Google 和 Apple 的代码:
Google:
import * as Google from "expo-google-app-auth";
try {
const result = await Google.logInAsync({
iosClientId:
"##############.apps.googleusercontent.com",
scopes: ["profile", "email"],
});
if (result.type === "success") {
const { idToken, accessToken } = result;
const credential = firebase.auth.GoogleAuthProvider.credential(
idToken,
accessToken
);
var user = firebase.auth().currentUser;
user.linkWithCredential(credential).then(async () => {}
Run Code Online (Sandbox Code Playgroud)
Apple:
import * as AppleAuthentication from "expo-apple-authentication";
import * as Crypto from "expo-crypto";
try {
const csrf = Math.random().toString(36).substring(2, 15);
const nonce = Math.random().toString(36).substring(2, 10);
const hashedNonce = await Crypto.digestStringAsync(
Crypto.CryptoDigestAlgorithm.SHA256,
nonce
);
const appleCredential = await AppleAuthentication.signInAsync({
requestedScopes: [
AppleAuthentication.AppleAuthenticationScope.FULL_NAME,
AppleAuthentication.AppleAuthenticationScope.EMAIL,
],
state: csrf,
nonce: hashedNonce,
});
const { identityToken, email, state } = appleCredential;
if (identityToken) {
const provider = new firebase.auth.OAuthProvider("apple.com");
const credential = provider.credential({
idToken: identityToken,
rawNonce: nonce, // nonce value from above
});
var user = firebase.auth().currentUser;
user.linkWithCredential(credential).then(async () => {})}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
387 次 |
| 最近记录: |