简体   繁体   English

如何从Google登录中获取身份验证令牌?

[英]How to get auth token from google sign in?

I'm trying to figure out how to get the auth token for the admin sdk from the google sign in on android. 我试图弄清楚如何从android上的google登录获取admin sdk的身份验证令牌。

I can use google sign in to get the account information, and I can get the phone to request permission. 我可以使用google登录获取帐户信息,也可以通过电话请求权限。 Whenever I try to get information it says that the request did not have the authorization required. 每当我尝试获取信息时,都会说该请求没有所需的授权。

After asking for a permission with: 在请求许可后:

GoogleSignIn.requestPermissions(activity, requestCode, account, *scopes)

And getting the account back in the onActivityResult method: 并使用onActivityResult方法重新获得帐户:

account = GoogleSignIn.getSignedInAccountFromIntent(data).getResult(ApiException::class.java)

So I'm pretty sure I need to get an auth token, but I am not sure how to get it? 因此,我很确定我需要获取一个auth令牌,但是我不确定如何获取它?

When you configure Google Sign-In you need to call the requestIdToken method and pass it your server's web client ID. 配置Google登录后,您需要调用requestIdToken方法并将其传递给服务器的Web客户端ID。 Your backend server can then use this token to authenticate. 然后,您的后端服务器可以使用此令牌进行身份验证。

The Task<GoogleSignInAccount> result should contain a GoogleSignInAccount object, which has a getIdToken() method that you can send to your backend server: Task<GoogleSignInAccount>结果应该包含一个GoogleSignInAccount对象,该对象具有可发送到后端服务器的getIdToken()方法:
https://developers.google.com/identity/sign-in/android/backend-auth https://developers.google.com/identity/sign-in/android/backend-auth

So I ended up figuring this out by using a library called appauth. 因此,我最终使用了名为appauth的库来解决这个问题。 It allows you to log in and get the access token for oauth servers. 它允许您登录并获取oauth服务器的访问令牌。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM