private async Task <AuthenticationTicket> DeserializeAuthorizationCodeAsync(string code, OpenIdConnectRequest request) { var notification = new DeserializeAuthorizationCodeContext(Context, Scheme, Options, request, code) { DataFormat = Options.AuthorizationCodeFormat }; await Provider.DeserializeAuthorizationCode(notification); if (notification.IsHandled || notification.Ticket != null) { notification.Ticket?.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AuthorizationCode); return(notification.Ticket); } if (notification.DataFormat == null) { throw new InvalidOperationException("A data formatter must be provided."); } var ticket = notification.DataFormat.Unprotect(code); if (ticket == null) { Logger.LogTrace("The received token was invalid or malformed: {Code}.", code); return(null); } // Note: since the data formatter relies on a data protector using different "purposes" strings // per token type, the ticket returned by Unprotect() is guaranteed to be an authorization code. ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.AuthorizationCode); Logger.LogTrace("The authorization code '{Code}' was successfully validated using " + "the specified token data format: {Claims} ; {Properties}.", code, ticket.Principal.Claims, ticket.Properties.Items); return(ticket); }
/// <summary> /// Represents an event called when deserializing an authorization code. /// </summary> /// <param name="context">The context instance associated with this event.</param> /// <returns>A <see cref="Task"/> that can be used to monitor the asynchronous operation.</returns> public virtual Task DeserializeAuthorizationCode(DeserializeAuthorizationCodeContext context) => OnDeserializeAuthorizationCode(context);