nativescript-google-login
将Google登录功能添加到您的Nativescript应用中。此插件为服务器端身份验证提供AuthCode
npm i --save nativescript-google-login
- 版本:1.4.0
- GitHub: https://github.com/pboulch/nativescript-google-login
- NPM: https://npmjs.net.cn/package/nativescript-google-login
- 下载量
- 昨日:1
- 上周:2
- 上月:15
Nativescript Google Login
将Google登录功能添加到您的Nativescript应用中。此插件为服务器端身份验证提供AuthCode
它受到了插件nativescript-social-login的启发
兼容Android X,iOS 13
截图
Android
iOS
依赖项
iOS
pod 'GoogleSignIn', '~> 5.0'
Android
implementation 'com.google.android.gms:play-services-auth:17.0.0'
安装
tns plugin add nativescript-google-login
iOS
获取OAuth客户端ID
从Google网站获取OAuth客户端ID
Info.plist
将以下内容添加到位于app/App_Resources/iOS的Info.plist文件中
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.123123123-172648sdfsd76f8s7d6f8sd</string>
<!-- It shoud look like this: com.googleusercontent.apps.123123123-172648sdfsd76f8s7d6f8sd -->
<!-- Get it from your GoogleService-Info.plist -->
<!-- Read more - https://developers.google.com/identity/sign-in/ios/start-integrating -->
</array>
</dict>
</array>
用法
```javascript
import { Component, OnInit } from "@angular/core";
import { GoogleLogin } from 'nativescript-google-login';
import * as application from "tns-core-modules/application";
import { isIOS } from "tns-core-modules/platform/platform";
@Component({
selector: "Home",
moduleId: module.id,
templateUrl: "./home.component.html"
})
export class HomeComponent implements OnInit {
constructor() {
// Use the component constructor to inject providers.
}
ngOnInit(): void {
// Init your component properties here.
if(isIOS){
GoogleLogin.init({
google: {
initialize: true,
serverClientId: "",
clientId: "",
isRequestAuthCode: true
},
viewController: application.ios.rootController
});
} else {
GoogleLogin.init({
google: {
initialize: true,
serverClientId: "",
clientId: "",
isRequestAuthCode: true
},
activity: application.android.foregroundActivity
});
}
}
login(): void {
GoogleLogin.login(result=>{
console.dir(result);
});
}
}
```
结果
```
==== object dump start ====
authCode: 4/sQFws5V78SYGYHxhxxZcpfTUNdf4tzWNyWwTesopXrfTM1SH5txNoPkaQ11hTkXxw3IJqXQcBu5iT6zlPFm42qs
code: 0
displayName: Firstname Lastname
photo: https://lh4.googleusercontent.com/-bxWt9qbfGOw/AAAAAAAAAAI/AAAAAAAAAAA/TkXxw3IJqXQcBu5iT61trzDOW8S1tcCYM4Q/s100/photo.jpg
error: undefined
id: 153078403269102635592
userToken: [email protected]
provider: google
==== object dump end ====
```
许可证
Apache许可证版本2.0,2004年1月