大家早上好。
在过去的5天里,我试图自己找到一些解决方案,但最后我不得不向你寻求帮助。
我使用Ionic (Cordova)开发了一个带有角的移动应用程序,并且我已经正确地将它发布在Google上。现在的问题在于苹果商店,因为它要求实现一个"Apple SignIn“按钮:从2020年4月开始,如果你有第三方登录(我有Facebook登录),你也必须使用苹果SignIn。
我在互联网上发现了一些有趣的解决方案,但它们都使用Firebase作为后端,我在我的服务器上使用了一个个人PHP后端。
解决方案1: cordova-plugin-apple-登录
以第一个解决方案为例,有一个不错的教程教授如何实现插件,但它使用Firebase。
安装:
npm i cordova-plugin-apple-login
ionic cordova plugin add cordova-plugin-apple-login执行情况:
declare var SignInWithApple: any;完全编码:
SignInWithApple.request({requestedScopes: [ SignInWithApple.Scope.Email, SignInWithApple.Scope.FullName ]})
.then((appleCredential) => {
const credential = new firebase.auth.OAuthProvider('apple.com').credential(appleCredential.identityToken);
this.afAuth.auth.signInWithCredential(credential)
.then((response) => {
console.log('Login successful');
})
.catch((error) => {
console.log(error);
alert('error:' + JSON.stringify(error));
});
});cordova-plugin-sign-in-with-apple解决方案2:
以第二个解决方案为例,Stack溢出中有一个答得好,它教我们如何实现插件,但它也使用Firebase。
安装:
ionic cordova plugin add cordova-plugin-sign-in-with-apple
npm i --save @ionic-native/sign-in-with-apple执行情况:
import { SignInWithApple, AppleSignInResponse, AppleSignInErrorResponse, ASAuthorizationAppleIDRequest } from '@ionic-native/sign-in-with-apple';完全编码:
async loginWithApple(): Promise<void> {
if (this.platform.is('cordova')) {
try {
const appleCredential: AppleSignInResponse = await SignInWithApple.signin({
requestedScopes: [
ASAuthorizationAppleIDRequest.ASAuthorizationScopeFullName,
ASAuthorizationAppleIDRequest.ASAuthorizationScopeEmail
]
});
const credential = new firebase.auth.OAuthProvider('apple.com').credential(
appleCredential.identityToken
);
this.afAuth.auth.signInWithCredential(credential)
.then((res) => {
console.log('Login successful', res);
})
.catch((error) => {
console.log(error);
});
} catch (error) {
console.log(error);
}
}
}我在寻找什么
正如您在这两种解决方案中看到的,有FireBase作为后端验证,但我正在搜索代码,以提取和保存两个令牌(Name和Email)中的一个变量,以便稍后在我的php后端发布用于验证的内容。
我认为这并不困难,但我正在为此付出很大的努力,我无法找到一个很好的解决方案。
对于Facebook登录,我使用下面的代码来提取和保存两个变量.我也想对苹果做同样的事情,而不是使用Firebase。
getUserDetail(userid: any) {
this.fb.api('/' + userid + '/?fields=id,email,name,picture', ['public_profile'])
.then(res => {
this.users = res;
this.emailFB = this.users['email'];
this.usernameFB = this.users['name'];
this.checkEmail(this.emailFB); //pass the email to do what I need in my PHP backend
})
.catch(e => {
console.log(e);
});
}发布于 2020-07-05 09:00:31
这是一个本地PHP -没有任何框架,您可以在任何框架工作中定制它。
https://gist.github.com/ameen-sarsour/e14a1d5bae5b61080dfdd5b1430c3e10
https://stackoverflow.com/questions/61540776
复制相似问题