简体   繁体   中英

Handle Refresh and AccessToken Oauth2 BoxApi

I am trying to use Box API for android sdk v2. I am able to successfully access the files after doing the first time authentication. I am able to do that using that same Access Token but after an hour it gets timedout. I dont know how to use that refresh token and get a new token from box api. Following is the Map which i use to create a BoxAndroidOAuthData object.

     Map<String, Object> authMap = new HashMap<String, Object>();
        authMap.put("access_token", sp.getString(ACCESSTOKEN, null));
        authMap.put("expires_in", 3600);
        authMap.put("restricted_to", "[]");
        authMap.put("token_type", "bearer");
        authMap.put("refresh_token", sp.getString(REFRESHTOKEN, null));

Here is the building of BoxAndroidOAuthData object.

    BoxAndroidOAuthData oauth = new BoxAndroidOAuthData(getOAuthData());
       BoxAndroidClient client = new BoxAndroidClient(
       TestBoxnetApplication.CLIENT_ID,TestBoxnetApplication.CLIENT_SECRET, null, null);
       client.authenticate(oauth);

I have even kept oAuthRefreshListener but i never get anything logged in there.

   client.addOAuthRefreshListener(new OAuthRefreshListener() {
       @Override
       public void onRefresh(IAuthData newAuthData) {
           System.out.println("new authentication token:"+ newAuthData.getAccessToken());
           saveOAuthData(newAuthData.getAccessToken(),newAuthData.getRefreshToken());
       }
   });

I don't have any idea how to use RefreshToken and get a new accesstoken and save it to use it further. Please help.

Thanks

are you sure that your refresh listener method is being called successfully?

if yes then the method suggested by André Restivo here save and use auth data in box android API should work,current problem i am facing is that my refresh listener method is never being called. i will solve it soon.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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