简体   繁体   English

无法生成刷新访问令牌

[英]Unable to generate refresh Access token

I am able to generate an access token but the response object return null for refresh token following is my code. 我能够生成访问令牌,但响应对象为刷新令牌返回null,这是我的代码。

JavaScript: JavaScript的:

 function connect_dfa(oauthurl,scop,redirect,clientId) {


            var width = 1024;
            var height = 512;
            var left = (screen.width / 2) - (width / 2);
            var top = (screen.height / 2) - (height / 2);
            var specs = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,width='+width+',height='+height+',top='+top+',left='+left;
            var url = oauthurl+"&scope="+scop+"&redirect_uri="+redirect+"&response_type=code&client_id="+clientId;
            alert (url);
            var win = window.open(url, 'scgid platform', specs, false);
        return false;
    }

once it redirect to redirect URL following code generate access token using the authentication code: 一旦重定向到重定向URL,以下代码将使用身份验证代码生成访问令牌:

flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY, CLIENT_ID, CLIENT_SECRET, SCOPES).build();


final TokenResponse response = flow.newTokenRequest(dfaToken).setRedirectUri(CALLBACK_URI)
        .execute();

System.out.println(response.getAccessToken());
System.out.println(response.getRefreshToken());

It return me an access token such as : ya29.CgH2ZBKtHUBr6uJtOs8q0q2vf_tllv_UYMF-Vcd-bODGOgoxqz05mzfDkymEGjVdmYuw2Os4FFpQPQ" but reuturn NULL for Refresh Token. 它向我返回了访问令牌,例如: ya29.CgH2ZBKtHUBr6uJtOs8q0q2vf_tllv_UYMF-Vcd-bODGOgoxqz05mzfDkymEGjVdmYuw2Os4FFpQPQ"但为刷新令牌重新返回NULL。

What m doing wrong since I am able to generate access token. 我做错了什么,因为我能够生成访问令牌。

You need to add "&access_type=offline" to the authorization window url in order to get refresh token. 您需要在授权窗口网址中添加"&access_type=offline" ,以获取刷新令牌。 For details: https://developers.google.com/accounts/docs/OAuth2WebServer#formingtheurl 有关详细信息: https : //developers.google.com/accounts/docs/OAuth2WebServer#formingtheurl

Steps to generate refresh token : 生成刷新令牌的步骤:

Step 1 : Configure return url of your App to http://0.0.0.0 . 步骤1:将您应用的返回网址配置为http://0.0.0.0 So that it will redirect you to localhost with code. 这样它将使用代码将您重定向到localhost。 Example : http://0.0.0.0/?state=authenticated&code=<code> 示例:http: http://0.0.0.0/?state=authenticated&code=<code>

Step 2: Navigate to below url with your client code 第2步:使用您的客户代码导航到以下网址

https://account.box.com/api/oauth2/authorize?response_type=code&client_id=<client_id>&state=authenticated

Step 3: Grant access to box api then copy <code> from your url. 步骤3:授予对Box api的访问权限,然后从您的网址中复制<code> Example : http://0.0.0.0/?state=authenticated&code=<code> 示例:http: http://0.0.0.0/?state=authenticated&code=<code>

Step 4: Do post request to https://api.box.com/oauth2/token with below parameters 步骤4:使用以下参数将请求发布到https://api.box.com/oauth2/token

grant_type = authorization_code,
    client_id = <client_id>,
    client_secret = <client_secret>,
    code = code you generated in step 3

This will return you below object: 这将使您返回以下对象:

access_token,
expires_in, 
restricted_to, 
refresh_token, 
token_type, 
created_time

Refresh token expiry : 60 days. 刷新令牌到期:60天。

Access Token expiry : 60 mins. 访问令牌到期时间:60分钟。

Note : Use code with in 10 sec 注意:在10秒钟内使用代码

Note : Every time you regenerate your access_token token you will get new refresh token. 注意:每次重新生成access_token令牌时,您都会获得新的刷新令牌。 For more information refer box documentations 有关更多信息,请参阅包装箱文档

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

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