如何使用Cordova和PHP后端(无FireBase)实现Apple SignIn

如何使用Cordova和PHP后端(无FireBase)实现Apple SignIn,php,ios,cordova,authentication,Php,Ios,Cordova,Authentication,大家早上好。 在过去的5天里,我一直试图自己找到一些解决方案,但最后我不得不向你寻求帮助。 我使用带有Angular的Ionic(Cordova)制作了一个移动应用程序,我已经在Google Play Store上正确发布了它。苹果商店现在的问题是,它要求实现一个“苹果登录””按钮:从2020年4月开始,如果你有第三方登录(我有Facebook登录),你也必须使用苹果登录。 我在internet上找到了一些有趣的解决方案,但它们都使用Firebase作为后端,我在服务器上使用了个人PHP后端。

大家早上好。
在过去的5天里,我一直试图自己找到一些解决方案,但最后我不得不向你寻求帮助。

我使用带有Angular的Ionic(Cordova)制作了一个移动应用程序,我已经在Google Play Store上正确发布了它。苹果商店现在的问题是,它要求实现一个“苹果登录””按钮:从2020年4月开始,如果你有第三方登录(我有Facebook登录),你也必须使用苹果登录。
我在internet上找到了一些有趣的解决方案,但它们都使用Firebase作为后端,我在服务器上使用了个人PHP后端。

解决方案1:cordova插件apple登录 以第一种解决方案为例,有一种方法可以教您如何实现插件,但它使用Firebase。

安装:

npm i cordova-plugin-apple-login
ionic cordova plugin add cordova-plugin-apple-login
ionic cordova plugin add cordova-plugin-sign-in-with-apple
npm i --save @ionic-native/sign-in-with-apple
实施:

declare var SignInWithApple: any;
import { SignInWithApple, AppleSignInResponse, AppleSignInErrorResponse, ASAuthorizationAppleIDRequest } from '@ionic-native/sign-in-with-apple';
完整代码:

   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));
      });
    });
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);
      }
    }
  }

解决方案2:使用apple登录cordova插件

以第二个解决方案为例,这里有一个栈内溢出,它告诉我们如何实现插件,但它也使用Firebase。

安装:

npm i cordova-plugin-apple-login
ionic cordova plugin add cordova-plugin-apple-login
ionic cordova plugin add cordova-plugin-sign-in-with-apple
npm i --save @ionic-native/sign-in-with-apple
实施:

declare var SignInWithApple: any;
import { SignInWithApple, AppleSignInResponse, AppleSignInErrorResponse, ASAuthorizationAppleIDRequest } from '@ionic-native/sign-in-with-apple';
完整代码:

   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));
      });
    });
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);
      }
    }
  }

这是一个原生PHP-没有任何框架,您可以在任何框架中自定义它


你找到答案了吗?我有一些问题…不,还是没有你找到解决办法了吗??