Esempio n. 1
0
        private static async Task HandleTokenRefreshFailure(HttpResponseMessage response)
        {
            // OneDrive specific logic: If the refresh token is expired, the server will return a 400 Bad Request
            // response with json content saying that the user must sign in.
            if (response.StatusCode == HttpStatusCode.BadRequest)
            {
                WindowsLiveError errorData = await response.Content.TryReadAsJsonAsync <WindowsLiveError>().ConfigureAwait(false);

                if (errorData != null && errorData.Error == "invalid_grant")
                {
                    throw new OneDriveTokenRefreshFailedException("The refresh token is expired.", errorData);
                }
            }

            // Dev note: Try to understand all of the refresh token failures. Any expected failures should be
            // throw as OneDriveTokenRefreshFailedException. This is here as a catch-all.
            var exception = new OneDriveHttpException("Failed to refresh token.", response.StatusCode);

            if (response.Headers.Contains("WwwAuthenticate"))
            {
                exception.Data["HttpAuthenticationHeader"] = response.Headers.WwwAuthenticate;
            }

            throw exception;
        }
Esempio n. 2
0
 public OneDriveTokenRefreshFailedException(string message, WindowsLiveError errorData)
     : base(message)
 {
     this.ErrorData = errorData;
 }