0
votes

I've asked this question on the UWP forum but have been directed here to see if anyone can help.

I use the OnlineIdAuthenticator from a C++ UWP app to access a users OneDrive files. This works well. However after an hour the token expires so I need to refresh it. I tried two approaches:

1) I took a look at the OneNote sample here: https://github.com/OneNoteDev/OneNoteAPISampleWinUniversal

Looking at AttemptAccessTokenRequest() within OneNoteServiceSamplesWinUniversal.Shared/OneNoteApi/LiveIdAuth.cs:

var createMessage = new HttpRequestMessage(HttpMethod.Post, MsaTokenRefreshUrl)
{
    Content = new StringContent(
    String.Format(CultureInfo.InvariantCulture, TokenRefreshRequestBody,
        ClientId,
        TokenRefreshRedirectUri,
       _refreshToken),
       Encoding.UTF8,
       TokenRefreshContentType)
    };

    var httpClient = new HttpClient();
    HttpResponseMessage response = await httpClient.SendAsync(createMessage);
    await ParseRefreshTokenResponse(response);
}

However I get a 400 response: error=invalid_request error_description=The provided request must include a 'refresh_token' input parameter.

I can't see any way to obtain the refresh token via the OnlineIdAuthenticator.

2) I call OnlineIdAuthenticator::AuthenticateUserAsync() again but this time only with a "wl.signin" scope, as mentioned in LiveAuthClient.cs from the LiveSDK:

https://github.com/liveservices/LiveSDK

This works and I get a new token! Unfortunately when I try to refresh it again (at the 2hr mark) it returns the same token and I then get a 401 unauthorized when I try to use it.

So has anyone successfully refreshed the access token via OnlineIdAuthenticator ? If so I'd appreciate knowing how you've done it.

Many thanks.

1

1 Answers

-1
votes

OnlineIdAuthenticator does not support refresh token as far as I know. did you try making direct POST request to https://consent.live.com/AccessToken.aspx? Check here for more details - https://msdn.microsoft.com/en-us/library/ff750952.aspx