I am implementing OAuth outside sharepoint in a java client to read a Sharepoint List using REST endpoints. While I have implemented everthing using Access token, I need to know what needs to be done when earlier Refresh token expires? How can I get a new refresh token? Because, when we request a access token using refresh token, it does not send new one....

Also since refresh token is valid for 6 months, how can I test this scenario to make sure that flow works.

2 Answers 2


Refresh token means user has given consent for auth for a particular period (6 months for SharePoint). When they expire, user has to grant that consent again to your App, so you need to redirect the user to your app page. You can read more on "Get a new context token" in https://msdn.microsoft.com/en-us/library/office/dn762763.aspx

However, if your Java client is a back-end application that operates without user interaction then you cannot redirect the user to app page. For this scenario, instead of refresh token you can use App Only Access permissions (of course user has to approve the app only access while installing the app).

With app only access, you can get a token and create clientContext without refresh token. Here you will be interacting with SharePoint just as an App (and not as an App + User). Take a look at GetAppOnlyAccessToken method in TokenHelper.cs (sorry, I have not worked with Java based SharePoint apps).



We can use apache httpclient to get new access token using the refresh token.

I would like show part of source:

    uri = "https://your http servce";    
    List<NameValuePair> params = new ArrayList<>();
    // curl https://url --data grant_type=refresh_token
    params.add(new BasicNameValuePair("grant_type","refresh_token"));
    // curl url --data client_id=280...
    params.add(new BasicNameValuePair("client_id","..."));
    params.add(new BasicNameValuePair("client_secret","..."));
    params.add(new BasicNameValuePair("resource","..."));
    params.add(new BasicNameValuePair("refresh_token","..."));

    String res = Uri_get.uri_post_proc(uri,params);
    Gson gson = new Gson();
    AccessToken accessToken = gson.fromJson(res, AccessToken.class);
    return accessToken.toString();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.