Ionic 4 使用 Apple 登录
Ionic 4 Sign In With Apple
拜托,你能帮帮我吗?
我想添加 Sign in with ionic 4 但没有文档我只找到这个 https://www.npmjs.com/package/cordova-plugin-sign-in-with-apple 但不知何故我无法使用。
非常感谢
import { SignInWithApple, AppleSignInResponse, AppleSignInErrorResponse, ASAuthorizationAppleIDRequest } from '@ionic-native/sign-in-with-apple/ngx';
constructor(private signInWithApple: SignInWithApple) { }
this.signInWithApple.signin({
requestedScopes: [
ASAuthorizationAppleIDRequest.ASAuthorizationScopeFullName,
ASAuthorizationAppleIDRequest.ASAuthorizationScopeEmail
]
})
.then((res: AppleSignInResponse) => {
// https://developer.apple.com/documentation/signinwithapplerestapi/verifying_a_user
alert('Send token to apple for verification: ' + res.identityToken);
console.log(res);
})
.catch((error: AppleSignInErrorResponse) => {
alert(error.code + ' ' + error.localizedDescription);
console.error(error);
});
示例,如果您也使用 Firebase
安装原生插件
npm i --save @ionic-native/sign-in-with-apple
在你的申请中
import {
SignInWithApple,
AppleSignInResponse,
AppleSignInErrorResponse,
ASAuthorizationAppleIDRequest
} from '@ionic-native/sign-in-with-apple';
constructor(private afAuth: AngularFireAuth) {}
async nativeAppleAuth(): Promise<void> {
try {
const appleCredential: AppleSignInResponse = await SignInWithApple.signin({
requestedScopes: [
ASAuthorizationAppleIDRequest.ASAuthorizationScopeFullName,
ASAuthorizationAppleIDRequest.ASAuthorizationScopeEmail
]
});
const credential = new firebase.auth.OAuthProvider('apple.com').credential(
appleCredential.identityToken
);
const response = await this.afAuth.auth.signInWithCredential(credential);
console.log('Login successful', response);
} catch (error) {
console.log(error);
}
}
拜托,你能帮帮我吗? 我想添加 Sign in with ionic 4 但没有文档我只找到这个 https://www.npmjs.com/package/cordova-plugin-sign-in-with-apple 但不知何故我无法使用。
非常感谢
import { SignInWithApple, AppleSignInResponse, AppleSignInErrorResponse, ASAuthorizationAppleIDRequest } from '@ionic-native/sign-in-with-apple/ngx';
constructor(private signInWithApple: SignInWithApple) { }
this.signInWithApple.signin({
requestedScopes: [
ASAuthorizationAppleIDRequest.ASAuthorizationScopeFullName,
ASAuthorizationAppleIDRequest.ASAuthorizationScopeEmail
]
})
.then((res: AppleSignInResponse) => {
// https://developer.apple.com/documentation/signinwithapplerestapi/verifying_a_user
alert('Send token to apple for verification: ' + res.identityToken);
console.log(res);
})
.catch((error: AppleSignInErrorResponse) => {
alert(error.code + ' ' + error.localizedDescription);
console.error(error);
});
示例,如果您也使用 Firebase
安装原生插件
npm i --save @ionic-native/sign-in-with-apple
在你的申请中
import {
SignInWithApple,
AppleSignInResponse,
AppleSignInErrorResponse,
ASAuthorizationAppleIDRequest
} from '@ionic-native/sign-in-with-apple';
constructor(private afAuth: AngularFireAuth) {}
async nativeAppleAuth(): Promise<void> {
try {
const appleCredential: AppleSignInResponse = await SignInWithApple.signin({
requestedScopes: [
ASAuthorizationAppleIDRequest.ASAuthorizationScopeFullName,
ASAuthorizationAppleIDRequest.ASAuthorizationScopeEmail
]
});
const credential = new firebase.auth.OAuthProvider('apple.com').credential(
appleCredential.identityToken
);
const response = await this.afAuth.auth.signInWithCredential(credential);
console.log('Login successful', response);
} catch (error) {
console.log(error);
}
}