private async Task <AuthenticationTicket> DeserializeRefreshTokenAsync(string token, OpenIdConnectMessage request)
        {
            var notification = new DeserializeRefreshTokenContext(Context, Options, request, token)
            {
                DataFormat = Options.RefreshTokenFormat
            };

            await Options.Provider.DeserializeRefreshToken(notification);

            // Directly return the authentication ticket if one
            // has been provided by DeserializeRefreshToken.
            if (notification.Ticket != null)
            {
                return(notification.Ticket);
            }

            var ticket = notification.DataFormat?.Unprotect(token);

            if (ticket == null)
            {
                return(null);
            }

            // Ensure the received ticket is an identity token.
            if (!ticket.IsRefreshToken())
            {
                Options.Logger.LogInformation("The received token was not a refresh token: {Token}.", token);

                return(null);
            }

            return(ticket);
        }
        private async Task <AuthenticationTicket> DeserializeRefreshTokenAsync(string token, OpenIdConnectRequest request)
        {
            var notification = new DeserializeRefreshTokenContext(Context, Options, request, token)
            {
                DataFormat = Options.RefreshTokenFormat
            };

            await Options.Provider.DeserializeRefreshToken(notification);

            if (notification.HandledResponse || notification.Ticket != null)
            {
                notification.Ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.RefreshToken);

                return(notification.Ticket);
            }

            else if (notification.Skipped)
            {
                return(null);
            }

            if (notification.DataFormat == null)
            {
                throw new InvalidOperationException("A data formatter must be provided.");
            }

            var ticket = notification.DataFormat.Unprotect(token);

            if (ticket == null)
            {
                Logger.LogTrace("The received token was invalid or malformed: {Token}.", token);

                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 a refresh token.
            ticket.SetTokenUsage(OpenIdConnectConstants.TokenUsages.RefreshToken);

            Logger.LogTrace("The refresh token '{Token}' was successfully validated using " +
                            "the specified token data format: {Claims} ; {Properties}.",
                            token, ticket.Identity.Claims, ticket.Properties.Dictionary);

            return(ticket);
        }
예제 #3
0
        private async Task <AuthenticationTicket> DeserializeRefreshTokenAsync(string token, OpenIdConnectRequest request)
        {
            var notification = new DeserializeRefreshTokenContext(Context, Options, request, token)
            {
                DataFormat = Options.RefreshTokenFormat
            };

            await Options.Provider.DeserializeRefreshToken(notification);

            if (notification.HandledResponse || notification.Ticket != null)
            {
                notification.Ticket.SetUsage(OpenIdConnectConstants.Usages.RefreshToken);

                return(notification.Ticket);
            }

            else if (notification.Skipped)
            {
                return(null);
            }

            var ticket = notification.DataFormat?.Unprotect(token);

            if (ticket == null)
            {
                return(null);
            }

            // Ensure the received ticket is an identity token.
            if (!ticket.IsRefreshToken())
            {
                Logger.LogDebug("The received token was not a refresh token: {Token}.", token);

                return(null);
            }

            return(ticket);
        }
 /// <summary>
 /// Represents an event called when deserializing a refresh token.
 /// </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 DeserializeRefreshToken(DeserializeRefreshTokenContext context)
 => OnDeserializeRefreshToken(context);