/// <summary> /// Requests an access token using a partially .initialized request message. /// </summary> /// <param name="request">The request message.</param> /// <param name="scopes">The scopes requested by the client.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns> /// The result of the request. /// </returns> private async Task<IAuthorizationState> RequestAccessTokenAsync(ScopedAccessTokenRequest request, IEnumerable<string> scopes, CancellationToken cancellationToken) { Requires.NotNull(request, "request"); var authorizationState = new AuthorizationState(scopes); request.ClientIdentifier = this.ClientIdentifier; this.ApplyClientCredential(request); request.Scope.UnionWith(authorizationState.Scope); var response = await this.Channel.RequestAsync(request, cancellationToken); var success = response as AccessTokenSuccessResponse; var failure = response as AccessTokenFailedResponse; ErrorUtilities.VerifyProtocol(success != null || failure != null, MessagingStrings.UnexpectedMessageReceivedOfMany); if (success != null) { authorizationState.Scope.Clear(); // clear the scope we requested so that the response will repopulate it. UpdateAuthorizationWithResponse(authorizationState, success); } else { // failure Logger.OAuth.Info("Credentials rejected by the Authorization Server."); authorizationState.Delete(); } return authorizationState; }
/// <summary> /// Requests an access token using a partially .initialized request message. /// </summary> /// <param name="request">The request message.</param> /// <param name="scopes">The scopes requested by the client.</param> /// <returns>The result of the request.</returns> private IAuthorizationState RequestAccessToken(ScopedAccessTokenRequest request, IEnumerable<string> scopes = null) { Requires.NotNull(request, "request"); var authorizationState = new AuthorizationState(scopes); request.ClientIdentifier = this.ClientIdentifier; request.ClientSecret = this.ClientSecret; request.Scope.UnionWith(authorizationState.Scope); var response = this.Channel.Request(request); var success = response as AccessTokenSuccessResponse; var failure = response as AccessTokenFailedResponse; ErrorUtilities.VerifyProtocol(success != null || failure != null, MessagingStrings.UnexpectedMessageReceivedOfMany); if (success != null) { UpdateAuthorizationWithResponse(authorizationState, success); } else { // failure Logger.OAuth.Info("Credentials rejected by the Authorization Server."); authorizationState.Delete(); } return authorizationState; }