# uni-oauth-google

## 使用说明

#### 关于 Credential Manager

[Credential Manager](https://developer.android.com/identity/sign-in/credential-manager?hl=zh-cn) 是Android 最新的登录鉴权方式.本插件基于`Credential Manager`实现了Google登录功能

#### 创建 google cloud 应用

在[google云管理后台](https://console.cloud.google.com/)，创建应用，并创建`OAuth 客户端 ID`,重点确保填写正确的包名和证书签名。

创建完成后，保存`客户端ID`用于代码调用。`客户端ID`的格式：`xxxxx.apps.googleusercontent.com`



#### 调用代码

以正确的包名和证书自定义基座后，可以使用下面的代码进行调用

uvue:

```vue
<template>
	<view>
		<button @tap="loginClick" >google登录</button>
		<button @tap="logoutClick" >google登出</button>
	</view>
</template>

<script>
	import { googleLogin, GoogleLoginOptions } from "@/uni_modules/uni-oauth-google"
	import { googleLogout, GoogleLogoutOptions } from "@/uni_modules/uni-oauth-google"
	
	export default {
		data() {
			return {
			}
		},
		methods: {
			loginClick:()=>{
				let options = {
					serverClientId:"xxxxx.apps.googleusercontent.com",
					success: (res : any) => {
					  console.log("success",res)
					},
					fail: (res : any) => {
					  console.log("fail",res)
					},
					complete: (res : any) => {
						console.log("complete",res)
					}
				} as GoogleLoginOptions;
				googleLogin(options);
			},
			logoutClick:()=>{
				let options = {
				  success: (res : any) => {
				    console.log("success",res)
				  },
				  fail: (res : any) => {
				    console.log("fail",res)
				  },
				  complete: (res : any|null) => {
				  	console.log("complete",res)
				  }
				} as GoogleLogoutOptions;
				
				googleLogout(options);
				
				
			}
		}
	}
</script>

<style>
	
</style>


```

vue:

```vue
<template>
	<view>
		<button @tap="loginClick" >google登录</button>
		<button @tap="logoutClick" >google登出</button>
	</view>
</template>

<script>
	import { googleLogin } from "@/uni_modules/uni-oauth-google"
	import { googleLogout } from "@/uni_modules/uni-oauth-google"
	
	
	export default {
		data() {
			return {
			}
		},
		methods: {
			
			loginClick:()=>{
				
				let options = {
					serverClientId:"xxxxxxxx.apps.googleusercontent.com",
					success: (res) => {
					  console.log("success",res)
					},
					fail: (res) => {
					  console.log("fail",res)
					},
					complete: (res) => {
						console.log("complete",res)
					}
				} 
				googleLogin(options);
			},
			logoutClick:()=>{
				
				let options = {
				  success: () => {
				    console.log("success")
				  },
				  fail: (res) => {
				    console.log("fail",res)
				  },
				  complete: (res) => {
				  	console.log("complete",res)
				  }
				}
				googleLogout(options);
			},
		}
	}
</script>

<style>

</style>


```

#### 错误码说明

|代码|说明|
|:--|:--|
|9010001|系统环境错误，请检查application/activity状态|
|9010002|用户参数配置错误，重点检查serverClientId是否正确|
|9010003|暂不支持的登录凭据|
|9010004|无法找到对应的凭据，可能是应用签名/包名不匹配或者与Google连接失败|
|9010005|登录组件缺失，请检查系统是否正确安装GMS|
|9010000|其他未知错误|
