如何启用“使用Apple ID登录";在Ionic 3应用程序中 [英] How to enable "Sign in with Apple Id" in Ionic 3 application

查看:69
本文介绍了如何启用“使用Apple ID登录";在Ionic 3应用程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的Ionic 3应用程序,该应用程序允许用户使用其Facebook或Google帐户登录.该应用程序与ASP.NET Core网站和api交互.我的理解是,Apple有时会要求此类应用程序支持使用Apple登录"

I have an existing Ionic 3 application that allows users to sign in with their Facebook or Google accounts. The app interacts with an ASP.NET Core website and api. My understanding is that at some point Apple will require such apps to support "Sign in with Apple"

在Facebook和Google中,有cordova插件(facebook4和googleplus),然后是一些服务器端代码来处理OAuth/OpenID Connect.我找不到用苹果登录"的任何cordova插件.我发现有关如何实施的文章api/web方面,但是在离子方面我不太清楚.如何在基于离子的iOS应用中启用使用Apple登录"?是否不需要插件(即可以全部使用javascript或应用内浏览器完成)?我知道应用内浏览器被Google的身份验证页面阻止,并且似乎对任何身份验证而言,首选本地"方法.

With Facebook and Google, there are cordova plugins (facebook4 and googleplus), and then some server-side code to handle the OAuth/OpenID Connect. I am not finding any cordova plugins for "Sign in with Apple". I have found an article about how to implement the api/web side of this, however I'm less clear on the Ionic side. How do I to enable "Sign in with Apple" in the ionic based iOS app? Is a plugin not needed (ie it can all be done with javascript or in-app browser)? I know in-app-browser is blocked by Google's auth page and it seems like a more "native" approach is preferred for any auth.

我知道这是新的,但是如果苹果公司开始要求它的话,似乎会有更多的开发人员遇到这个问题.我是否误解了有关此要求的提示?

I understand this is new, but it seems like more developers would have this issue if Apple is going to start requiring it. Am I misunderstanding something about this being required soon?

推荐答案

您可以使用以下离子包装器:

You could use this Ionic wrapper : https://www.npmjs.com/package/@ionic-native/sign-in-with-apple

安装插件和包装器:

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';

使用示例(带有Firebase):

An example of use (with firebase) :

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

这篇关于如何启用“使用Apple ID登录";在Ionic 3应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆