获取空刷新令牌

编程入门 行业动态 更新时间:2024-10-27 17:12:47
本文介绍了获取空刷新令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用google-api-java-client版本1.8-beta进行oAuth2身份验证。一切正常,直到我得到GoogleTokenResponse对象,它具有访问令牌但没有刷新令牌。 构建请求url我使用以下方法:

... googleAuthenticationUrl = new GoogleAuthorizationCodeRequestUrl (CLIENT_ID,callBackUrl,作用域).build(); ...

在获取请求令牌时,我使用此访问令牌进行交换 $ GoogleTokenResponse tokenResponse =新的GoogleAuthorizationCodeTokenRequest(新的NetHttpTransport(),新的JacksonFactory(),CLIENT_ID ,CLIENT_SECRET,request.getParameter(CODE_URL_PARAM),callBackUrl).execute(); ...

返回的GoogleTokenResponse对象不包含刷新标记:

{access_token:ya29.AH..etc ... 9-Y,expires_in:3600,token_type :持票人}

请您在这个问题上说清楚我的看法?感谢您的帮助!

解决方案

在构建请求URL时,应设置访问类型:

$ b $

requestUrl = new GoogleAuthorizationCodeRequestUrl(googleClientId,callBackUrl,scopes).setAccessType(offline)。build();

如 page 设置此参数的建议:您明确地将access_type参数设置为脱机,因为我们预计当联机值引入时,它将作为默认行为。这可能会导致应用程序发生的意外更改,因为它会影响您的应用程序允许刷新访问令牌的方式。通过显式设置参数值为脱机状态,可以避免应用程序功能发生任何更改。 [...]

I'm using the google-api-java-client version 1.8-beta for oAuth2 authentication with Google accounts. Everything fine until I get the GoogleTokenResponse object, which has the access token but not refresh token. To build the request url I user the following method :

... googleAuthenticationUrl = new GoogleAuthorizationCodeRequestUrl(CLIENT_ID, callBackUrl, scopes).build(); ...

When getting the request token I exchange it with an access token in this line :

... GoogleTokenResponse tokenResponse = new GoogleAuthorizationCodeTokenRequest(new NetHttpTransport(), new JacksonFactory(), CLIENT_ID, CLIENT_SECRET, request.getParameter(CODE_URL_PARAM), callBackUrl).execute(); ...

The returned GoogleTokenResponse object does not contains the refresh token :

{"access_token":"ya29.AH..etc...9-Y","expires_in":3600,"token_type":"Bearer"}

Could you please shed my light on this issue ? Thank you very much for your help!

解决方案

When building the request Url, you should set the Access Type :

requestUrl = new GoogleAuthorizationCodeRequestUrl(googleClientId, callBackUrl, scopes).setAccessType("offline").build();

As described in this page setting this parameter is recommended :

[...] We recommend that you explicitly set the access_type parameter to offline because we anticipate that when the online value is introduced, it will be as the default behavior. This could cause unexpected changes in your application since it would affect the way that your application is allowed to refresh access tokens. By explicitly setting the parameter value to offline, you can avoid any changes in your application's functionality. [...]

更多推荐

获取空刷新令牌

本文发布于:2023-11-26 15:36:58,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:令牌

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!