如何在 Nativescript iOS 应用程序中使用 Google 实现登录?

How to implement Login with Google in a Nativescript iOS app?

我正在尝试通过 nativescript-social-login 插件在 Nativescript 中实现 google 的 id 提供程序登录,到目前为止它在 Android 中运行良好,但它不起作用iOS.

按照插件创建者的说明,我注意到一些 类 需要额外的打字稿定义文件,所以在研究这个问题时我发现使用 google 实现登录的方法已经改变最近在 iOS 中,一些 pods 已被弃用。我尝试遵循新方法,我自己为 GIDSignIn 委托定义了一个 d.ts 文件,如下所示

declare class GIDSignIn{
   public static sharedInstance(): GIDSignIn;
   public handleURLSourceApplication(url: NSURL, sourceApplication:NSString, annotiation: id): boolean;
}

但即使通过这种方式编译应用程序,只要我点击登录按钮它就会崩溃。

通过检查 xcode 中的构建,我收到一条警告,指出尚未配置 Firebase 实例,我应该如何在 Typescript 代码中配置它

使用 nativescript-oauth 插件进行社交登录。

Example

login.component.ts:-

`import * as tnsOAuthModule from 'nativescript-oauth';

public login() {

    tnsOAuthModule.login()

        .then(() => {

            let tokenModule = JSON.stringify(tnsOAuthModule);

            let refereshToken = JSON.parse(tokenModule).instance.tokenResult.refreshToken;

            this.getRefereshActiveToken(refereshToken);
        })

        .catch((er) => {

            console.error('error logging in');

            console.dir(er);

        });

}`

Add google authentication configuration in main.ts file Like.

`import * as tnsOAuthModule from 'nativescript-oauth';

var myInitOptions: tnsOAuthModule.ITnsOAuthCredentials = {

authority: '',

authorizeEndpoint: '',

tokenEndpoint: '',

clientId: '',

redirectUri: 'urn:ietf:wg:oauth:2.0:oob',

responseType: "code",

scope: 'openid',

};

tnsOAuthModule.initCustom({

credentials: myInitOptions,

cookieDomains: ['http://demoweb.net'],

});`

对于 IOS 仅在 App_Resources -> iOS -> [=27= 中的 google 上成功验证后才添加此代码用于重定向] 文件.

<key>CFBundleURLTypes</key>

<array>

    <dict>

        <key>CFBundleTypeRole</key>

        <string>Editor</string>

        <key>CFBundleURLName</key>

        <string>app_id</string>

        <key>CFBundleURLSchemes</key>

        <array>

            <string>appauth</string>

        </array>

    </dict>

</array>

<key>NSAppTransportSecurity</key>

<dict>

    <key>NSAllowsArbitraryLoads</key>

    <true/>

</dict>