Switch to AuthenticationTicket in OAuth event
This commit is contained in:
parent
2a939287bc
commit
7a23028527
|
|
@ -38,7 +38,8 @@ namespace Microsoft.AspNet.Authentication.Facebook
|
||||||
|
|
||||||
var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
|
var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
|
||||||
|
|
||||||
var context = new OAuthCreatingTicketContext(new ClaimsPrincipal(identity), properties, Context, Options, Backchannel, tokens, payload);
|
var ticket = new AuthenticationTicket(new ClaimsPrincipal(identity), properties, Options.AuthenticationScheme);
|
||||||
|
var context = new OAuthCreatingTicketContext(ticket, Context, Options, Backchannel, tokens, payload);
|
||||||
|
|
||||||
var identifier = FacebookHelper.GetId(payload);
|
var identifier = FacebookHelper.GetId(payload);
|
||||||
if (!string.IsNullOrEmpty(identifier))
|
if (!string.IsNullOrEmpty(identifier))
|
||||||
|
|
@ -78,7 +79,7 @@ namespace Microsoft.AspNet.Authentication.Facebook
|
||||||
|
|
||||||
await Options.Events.CreatingTicket(context);
|
await Options.Events.CreatingTicket(context);
|
||||||
|
|
||||||
return new AuthenticationTicket(context.Principal, context.Properties, context.Options.AuthenticationScheme);
|
return context.Ticket;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GenerateAppSecretProof(string accessToken)
|
private string GenerateAppSecretProof(string accessToken)
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,8 @@ namespace Microsoft.AspNet.Authentication.Google
|
||||||
|
|
||||||
var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
|
var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
|
||||||
|
|
||||||
var context = new OAuthCreatingTicketContext(new ClaimsPrincipal(identity), properties, Context, Options, Backchannel, tokens, payload);
|
var ticket = new AuthenticationTicket(new ClaimsPrincipal(identity), properties, Options.AuthenticationScheme);
|
||||||
|
var context = new OAuthCreatingTicketContext(ticket, Context, Options, Backchannel, tokens, payload);
|
||||||
|
|
||||||
var identifier = GoogleHelper.GetId(payload);
|
var identifier = GoogleHelper.GetId(payload);
|
||||||
if (!string.IsNullOrEmpty(identifier))
|
if (!string.IsNullOrEmpty(identifier))
|
||||||
|
|
@ -72,7 +73,7 @@ namespace Microsoft.AspNet.Authentication.Google
|
||||||
|
|
||||||
await Options.Events.CreatingTicket(context);
|
await Options.Events.CreatingTicket(context);
|
||||||
|
|
||||||
return new AuthenticationTicket(context.Principal, context.Properties, context.Options.AuthenticationScheme);
|
return context.Ticket;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Abstract this properties override pattern into the base class?
|
// TODO: Abstract this properties override pattern into the base class?
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
await Options.Events.ReceivingToken(receivingTokenContext);
|
await Options.Events.ReceivingToken(receivingTokenContext);
|
||||||
if (receivingTokenContext.HandledResponse)
|
if (receivingTokenContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return AuthenticateResult.Success(receivingTokenContext.AuthenticationTicket);
|
return AuthenticateResult.Success(receivingTokenContext.Ticket);
|
||||||
}
|
}
|
||||||
if (receivingTokenContext.Skipped)
|
if (receivingTokenContext.Skipped)
|
||||||
{
|
{
|
||||||
|
|
@ -77,7 +77,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
await Options.Events.ReceivedToken(receivedTokenContext);
|
await Options.Events.ReceivedToken(receivedTokenContext);
|
||||||
if (receivedTokenContext.HandledResponse)
|
if (receivedTokenContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return AuthenticateResult.Success(receivedTokenContext.AuthenticationTicket);
|
return AuthenticateResult.Success(receivedTokenContext.Ticket);
|
||||||
}
|
}
|
||||||
if (receivedTokenContext.Skipped)
|
if (receivedTokenContext.Skipped)
|
||||||
{
|
{
|
||||||
|
|
@ -139,13 +139,13 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
var ticket = new AuthenticationTicket(principal, new AuthenticationProperties(), Options.AuthenticationScheme);
|
var ticket = new AuthenticationTicket(principal, new AuthenticationProperties(), Options.AuthenticationScheme);
|
||||||
var validatedTokenContext = new ValidatedTokenContext(Context, Options)
|
var validatedTokenContext = new ValidatedTokenContext(Context, Options)
|
||||||
{
|
{
|
||||||
AuthenticationTicket = ticket
|
Ticket = ticket
|
||||||
};
|
};
|
||||||
|
|
||||||
await Options.Events.ValidatedToken(validatedTokenContext);
|
await Options.Events.ValidatedToken(validatedTokenContext);
|
||||||
if (validatedTokenContext.HandledResponse)
|
if (validatedTokenContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return AuthenticateResult.Success(validatedTokenContext.AuthenticationTicket);
|
return AuthenticateResult.Success(validatedTokenContext.Ticket);
|
||||||
}
|
}
|
||||||
if (validatedTokenContext.Skipped)
|
if (validatedTokenContext.Skipped)
|
||||||
{
|
{
|
||||||
|
|
@ -166,7 +166,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
await Options.Events.AuthenticationFailed(authenticationFailedContext);
|
await Options.Events.AuthenticationFailed(authenticationFailedContext);
|
||||||
if (authenticationFailedContext.HandledResponse)
|
if (authenticationFailedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return AuthenticateResult.Success(authenticationFailedContext.AuthenticationTicket);
|
return AuthenticateResult.Success(authenticationFailedContext.Ticket);
|
||||||
}
|
}
|
||||||
if (authenticationFailedContext.Skipped)
|
if (authenticationFailedContext.Skipped)
|
||||||
{
|
{
|
||||||
|
|
@ -190,7 +190,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
await Options.Events.AuthenticationFailed(authenticationFailedContext);
|
await Options.Events.AuthenticationFailed(authenticationFailedContext);
|
||||||
if (authenticationFailedContext.HandledResponse)
|
if (authenticationFailedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return AuthenticateResult.Success(authenticationFailedContext.AuthenticationTicket);
|
return AuthenticateResult.Success(authenticationFailedContext.Ticket);
|
||||||
}
|
}
|
||||||
if (authenticationFailedContext.Skipped)
|
if (authenticationFailedContext.Skipped)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,8 @@ namespace Microsoft.AspNet.Authentication.MicrosoftAccount
|
||||||
|
|
||||||
var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
|
var payload = JObject.Parse(await response.Content.ReadAsStringAsync());
|
||||||
|
|
||||||
var context = new OAuthCreatingTicketContext(new ClaimsPrincipal(identity), properties, Context, Options, Backchannel, tokens, payload);
|
var ticket = new AuthenticationTicket(new ClaimsPrincipal(identity), properties, Options.AuthenticationScheme);
|
||||||
|
var context = new OAuthCreatingTicketContext(ticket, Context, Options, Backchannel, tokens, payload);
|
||||||
var identifier = MicrosoftAccountHelper.GetId(payload);
|
var identifier = MicrosoftAccountHelper.GetId(payload);
|
||||||
if (!string.IsNullOrEmpty(identifier))
|
if (!string.IsNullOrEmpty(identifier))
|
||||||
{
|
{
|
||||||
|
|
@ -50,8 +51,7 @@ namespace Microsoft.AspNet.Authentication.MicrosoftAccount
|
||||||
}
|
}
|
||||||
|
|
||||||
await Options.Events.CreatingTicket(context);
|
await Options.Events.CreatingTicket(context);
|
||||||
|
return context.Ticket;
|
||||||
return new AuthenticationTicket(context.Principal, context.Properties, context.Options.AuthenticationScheme);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,36 +19,32 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new <see cref="OAuthCreatingTicketContext"/>.
|
/// Initializes a new <see cref="OAuthCreatingTicketContext"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="principal">The <see cref="ClaimsPrincipal"/> representing the user.</param>
|
/// <param name="ticket">The <see cref="AuthenticationTicket"/>.</param>
|
||||||
/// <param name="properties">Property bag for common authentication properties.</param>
|
|
||||||
/// <param name="context">The HTTP environment.</param>
|
/// <param name="context">The HTTP environment.</param>
|
||||||
/// <param name="options">The options used by the authentication middleware.</param>
|
/// <param name="options">The options used by the authentication middleware.</param>
|
||||||
/// <param name="backchannel">The HTTP client used by the authentication middleware</param>
|
/// <param name="backchannel">The HTTP client used by the authentication middleware</param>
|
||||||
/// <param name="tokens">The tokens returned from the token endpoint.</param>
|
/// <param name="tokens">The tokens returned from the token endpoint.</param>
|
||||||
public OAuthCreatingTicketContext(
|
public OAuthCreatingTicketContext(
|
||||||
ClaimsPrincipal principal,
|
AuthenticationTicket ticket,
|
||||||
AuthenticationProperties properties,
|
|
||||||
HttpContext context,
|
HttpContext context,
|
||||||
OAuthOptions options,
|
OAuthOptions options,
|
||||||
HttpClient backchannel,
|
HttpClient backchannel,
|
||||||
OAuthTokenResponse tokens)
|
OAuthTokenResponse tokens)
|
||||||
: this(principal, properties, context, options, backchannel, tokens, user: new JObject())
|
: this(ticket, context, options, backchannel, tokens, user: new JObject())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new <see cref="OAuthCreatingTicketContext"/>.
|
/// Initializes a new <see cref="OAuthCreatingTicketContext"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="principal">The <see cref="ClaimsPrincipal"/> representing the user.</param>
|
/// <param name="ticket">The <see cref="AuthenticationTicket"/>.</param>
|
||||||
/// <param name="properties">Property bag for common authentication properties.</param>
|
|
||||||
/// <param name="context">The HTTP environment.</param>
|
/// <param name="context">The HTTP environment.</param>
|
||||||
/// <param name="options">The options used by the authentication middleware.</param>
|
/// <param name="options">The options used by the authentication middleware.</param>
|
||||||
/// <param name="backchannel">The HTTP client used by the authentication middleware</param>
|
/// <param name="backchannel">The HTTP client used by the authentication middleware</param>
|
||||||
/// <param name="tokens">The tokens returned from the token endpoint.</param>
|
/// <param name="tokens">The tokens returned from the token endpoint.</param>
|
||||||
/// <param name="user">The JSON-serialized user.</param>
|
/// <param name="user">The JSON-serialized user.</param>
|
||||||
public OAuthCreatingTicketContext(
|
public OAuthCreatingTicketContext(
|
||||||
ClaimsPrincipal principal,
|
AuthenticationTicket ticket,
|
||||||
AuthenticationProperties properties,
|
|
||||||
HttpContext context,
|
HttpContext context,
|
||||||
OAuthOptions options,
|
OAuthOptions options,
|
||||||
HttpClient backchannel,
|
HttpClient backchannel,
|
||||||
|
|
@ -85,8 +81,7 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
||||||
Backchannel = backchannel;
|
Backchannel = backchannel;
|
||||||
User = user;
|
User = user;
|
||||||
Options = options;
|
Options = options;
|
||||||
Principal = principal;
|
Ticket = ticket;
|
||||||
Properties = properties;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public OAuthOptions Options { get; }
|
public OAuthOptions Options { get; }
|
||||||
|
|
@ -140,19 +135,14 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
||||||
public HttpClient Backchannel { get; }
|
public HttpClient Backchannel { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the <see cref="ClaimsPrincipal"/> representing the user.
|
/// The <see cref="AuthenticationTicket"/> that will be created.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ClaimsPrincipal Principal { get; set; }
|
public AuthenticationTicket Ticket { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the main identity exposed by <see cref="Principal"/>.
|
/// Gets the main identity exposed by <see cref="Ticket"/>.
|
||||||
/// This property returns <c>null</c> when <see cref="Principal"/> is <c>null</c>.
|
/// This property returns <c>null</c> when <see cref="Ticket"/> is <c>null</c>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ClaimsIdentity Identity => Principal?.Identity as ClaimsIdentity;
|
public ClaimsIdentity Identity => Ticket?.Principal.Identity as ClaimsIdentity;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets a property bag for common authentication properties.
|
|
||||||
/// </summary>
|
|
||||||
public AuthenticationProperties Properties { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -155,16 +155,10 @@ namespace Microsoft.AspNet.Authentication.OAuth
|
||||||
|
|
||||||
protected virtual async Task<AuthenticationTicket> CreateTicketAsync(ClaimsIdentity identity, AuthenticationProperties properties, OAuthTokenResponse tokens)
|
protected virtual async Task<AuthenticationTicket> CreateTicketAsync(ClaimsIdentity identity, AuthenticationProperties properties, OAuthTokenResponse tokens)
|
||||||
{
|
{
|
||||||
var context = new OAuthCreatingTicketContext(new ClaimsPrincipal(identity), properties, Context, Options, Backchannel, tokens);
|
var ticket = new AuthenticationTicket(new ClaimsPrincipal(identity), properties, Options.AuthenticationScheme);
|
||||||
|
var context = new OAuthCreatingTicketContext(ticket, Context, Options, Backchannel, tokens);
|
||||||
await Options.Events.CreatingTicket(context);
|
await Options.Events.CreatingTicket(context);
|
||||||
|
return context.Ticket;
|
||||||
if (context.Principal?.Identity == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new AuthenticationTicket(context.Principal, context.Properties, Options.AuthenticationScheme);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task<bool> HandleUnauthorizedAsync(ChallengeContext context)
|
protected override async Task<bool> HandleUnauthorizedAsync(ChallengeContext context)
|
||||||
|
|
|
||||||
|
|
@ -332,7 +332,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
var messageReceivedContext = await RunMessageReceivedEventAsync(message);
|
var messageReceivedContext = await RunMessageReceivedEventAsync(message);
|
||||||
if (messageReceivedContext.HandledResponse)
|
if (messageReceivedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return AuthenticateResult.Success(messageReceivedContext.AuthenticationTicket);
|
return AuthenticateResult.Success(messageReceivedContext.Ticket);
|
||||||
}
|
}
|
||||||
else if (messageReceivedContext.Skipped)
|
else if (messageReceivedContext.Skipped)
|
||||||
{
|
{
|
||||||
|
|
@ -387,7 +387,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
if (authorizationResponseReceivedContext.HandledResponse)
|
if (authorizationResponseReceivedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
Logger.LogDebug(16, "AuthorizationResponseReceived.HandledResponse");
|
Logger.LogDebug(16, "AuthorizationResponseReceived.HandledResponse");
|
||||||
return AuthenticateResult.Success(authorizationResponseReceivedContext.AuthenticationTicket);
|
return AuthenticateResult.Success(authorizationResponseReceivedContext.Ticket);
|
||||||
}
|
}
|
||||||
else if (authorizationResponseReceivedContext.Skipped)
|
else if (authorizationResponseReceivedContext.Skipped)
|
||||||
{
|
{
|
||||||
|
|
@ -428,7 +428,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
var authenticationFailedContext = await RunAuthenticationFailedEventAsync(message, exception);
|
var authenticationFailedContext = await RunAuthenticationFailedEventAsync(message, exception);
|
||||||
if (authenticationFailedContext.HandledResponse)
|
if (authenticationFailedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return AuthenticateResult.Success(authenticationFailedContext.AuthenticationTicket);
|
return AuthenticateResult.Success(authenticationFailedContext.Ticket);
|
||||||
}
|
}
|
||||||
else if (authenticationFailedContext.Skipped)
|
else if (authenticationFailedContext.Skipped)
|
||||||
{
|
{
|
||||||
|
|
@ -454,7 +454,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
var authorizationCodeReceivedContext = await RunAuthorizationCodeReceivedEventAsync(message, properties, ticket, jwt);
|
var authorizationCodeReceivedContext = await RunAuthorizationCodeReceivedEventAsync(message, properties, ticket, jwt);
|
||||||
if (authorizationCodeReceivedContext.HandledResponse)
|
if (authorizationCodeReceivedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return AuthenticateResult.Success(authorizationCodeReceivedContext.AuthenticationTicket);
|
return AuthenticateResult.Success(authorizationCodeReceivedContext.Ticket);
|
||||||
}
|
}
|
||||||
else if (authorizationCodeReceivedContext.Skipped)
|
else if (authorizationCodeReceivedContext.Skipped)
|
||||||
{
|
{
|
||||||
|
|
@ -471,7 +471,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
var authorizationCodeRedeemedContext = await RunTokenResponseReceivedEventAsync(message, tokenEndpointResponse, properties);
|
var authorizationCodeRedeemedContext = await RunTokenResponseReceivedEventAsync(message, tokenEndpointResponse, properties);
|
||||||
if (authorizationCodeRedeemedContext.HandledResponse)
|
if (authorizationCodeRedeemedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return AuthenticateResult.Success(authorizationCodeRedeemedContext.AuthenticationTicket);
|
return AuthenticateResult.Success(authorizationCodeRedeemedContext.Ticket);
|
||||||
}
|
}
|
||||||
else if (authorizationCodeRedeemedContext.Skipped)
|
else if (authorizationCodeRedeemedContext.Skipped)
|
||||||
{
|
{
|
||||||
|
|
@ -504,13 +504,13 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
var authenticationValidatedContext = await RunAuthenticationValidatedEventAsync(message, ticket, properties, tokenEndpointResponse);
|
var authenticationValidatedContext = await RunAuthenticationValidatedEventAsync(message, ticket, properties, tokenEndpointResponse);
|
||||||
if (authenticationValidatedContext.HandledResponse)
|
if (authenticationValidatedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return AuthenticateResult.Success(authenticationValidatedContext.AuthenticationTicket);
|
return AuthenticateResult.Success(authenticationValidatedContext.Ticket);
|
||||||
}
|
}
|
||||||
else if (authenticationValidatedContext.Skipped)
|
else if (authenticationValidatedContext.Skipped)
|
||||||
{
|
{
|
||||||
return AuthenticateResult.Skip();
|
return AuthenticateResult.Skip();
|
||||||
}
|
}
|
||||||
ticket = authenticationValidatedContext.AuthenticationTicket;
|
ticket = authenticationValidatedContext.Ticket;
|
||||||
|
|
||||||
if (Options.SaveTokensAsClaims)
|
if (Options.SaveTokensAsClaims)
|
||||||
{
|
{
|
||||||
|
|
@ -553,14 +553,14 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
var authenticationValidatedContext = await RunAuthenticationValidatedEventAsync(message, ticket, properties, tokenEndpointResponse: null);
|
var authenticationValidatedContext = await RunAuthenticationValidatedEventAsync(message, ticket, properties, tokenEndpointResponse: null);
|
||||||
if (authenticationValidatedContext.HandledResponse)
|
if (authenticationValidatedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return AuthenticateResult.Success(authenticationValidatedContext.AuthenticationTicket);
|
return AuthenticateResult.Success(authenticationValidatedContext.Ticket);
|
||||||
}
|
}
|
||||||
else if (authenticationValidatedContext.Skipped)
|
else if (authenticationValidatedContext.Skipped)
|
||||||
{
|
{
|
||||||
return AuthenticateResult.Skip();
|
return AuthenticateResult.Skip();
|
||||||
}
|
}
|
||||||
message = authenticationValidatedContext.ProtocolMessage;
|
message = authenticationValidatedContext.ProtocolMessage;
|
||||||
ticket = authenticationValidatedContext.AuthenticationTicket;
|
ticket = authenticationValidatedContext.Ticket;
|
||||||
|
|
||||||
// Hybrid Flow
|
// Hybrid Flow
|
||||||
if (message.Code != null)
|
if (message.Code != null)
|
||||||
|
|
@ -568,14 +568,14 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
var authorizationCodeReceivedContext = await RunAuthorizationCodeReceivedEventAsync(message, properties, ticket, jwt);
|
var authorizationCodeReceivedContext = await RunAuthorizationCodeReceivedEventAsync(message, properties, ticket, jwt);
|
||||||
if (authorizationCodeReceivedContext.HandledResponse)
|
if (authorizationCodeReceivedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return AuthenticateResult.Success(authorizationCodeReceivedContext.AuthenticationTicket);
|
return AuthenticateResult.Success(authorizationCodeReceivedContext.Ticket);
|
||||||
}
|
}
|
||||||
else if (authorizationCodeReceivedContext.Skipped)
|
else if (authorizationCodeReceivedContext.Skipped)
|
||||||
{
|
{
|
||||||
return AuthenticateResult.Skip();
|
return AuthenticateResult.Skip();
|
||||||
}
|
}
|
||||||
message = authorizationCodeReceivedContext.ProtocolMessage;
|
message = authorizationCodeReceivedContext.ProtocolMessage;
|
||||||
ticket = authorizationCodeReceivedContext.AuthenticationTicket;
|
ticket = authorizationCodeReceivedContext.Ticket;
|
||||||
|
|
||||||
if (Options.SaveTokensAsClaims)
|
if (Options.SaveTokensAsClaims)
|
||||||
{
|
{
|
||||||
|
|
@ -666,13 +666,13 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
var userInformationReceivedContext = await RunUserInformationReceivedEventAsync(ticket, message, user);
|
var userInformationReceivedContext = await RunUserInformationReceivedEventAsync(ticket, message, user);
|
||||||
if (userInformationReceivedContext.HandledResponse)
|
if (userInformationReceivedContext.HandledResponse)
|
||||||
{
|
{
|
||||||
return userInformationReceivedContext.AuthenticationTicket;
|
return userInformationReceivedContext.Ticket;
|
||||||
}
|
}
|
||||||
else if (userInformationReceivedContext.Skipped)
|
else if (userInformationReceivedContext.Skipped)
|
||||||
{
|
{
|
||||||
return ticket;
|
return ticket;
|
||||||
}
|
}
|
||||||
ticket = userInformationReceivedContext.AuthenticationTicket;
|
ticket = userInformationReceivedContext.Ticket;
|
||||||
user = userInformationReceivedContext.User;
|
user = userInformationReceivedContext.User;
|
||||||
|
|
||||||
Options.ProtocolValidator.ValidateUserInfoResponse(new OpenIdConnectProtocolValidationContext()
|
Options.ProtocolValidator.ValidateUserInfoResponse(new OpenIdConnectProtocolValidationContext()
|
||||||
|
|
@ -954,7 +954,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
Code = message.Code,
|
Code = message.Code,
|
||||||
ProtocolMessage = message,
|
ProtocolMessage = message,
|
||||||
RedirectUri = redirectUri,
|
RedirectUri = redirectUri,
|
||||||
AuthenticationTicket = ticket,
|
Ticket = ticket,
|
||||||
JwtSecurityToken = jwt
|
JwtSecurityToken = jwt
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -996,7 +996,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
{
|
{
|
||||||
var authenticationValidatedContext = new AuthenticationValidatedContext(Context, Options, properties)
|
var authenticationValidatedContext = new AuthenticationValidatedContext(Context, Options, properties)
|
||||||
{
|
{
|
||||||
AuthenticationTicket = ticket,
|
Ticket = ticket,
|
||||||
ProtocolMessage = message,
|
ProtocolMessage = message,
|
||||||
TokenEndpointResponse = tokenEndpointResponse,
|
TokenEndpointResponse = tokenEndpointResponse,
|
||||||
};
|
};
|
||||||
|
|
@ -1020,7 +1020,7 @@ namespace Microsoft.AspNet.Authentication.OpenIdConnect
|
||||||
|
|
||||||
var userInformationReceivedContext = new UserInformationReceivedContext(Context, Options)
|
var userInformationReceivedContext = new UserInformationReceivedContext(Context, Options)
|
||||||
{
|
{
|
||||||
AuthenticationTicket = ticket,
|
Ticket = ticket,
|
||||||
ProtocolMessage = message,
|
ProtocolMessage = message,
|
||||||
User = user,
|
User = user,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Authentication
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Discontinue all processing for this request and return to the client.
|
/// Discontinue all processing for this request and return to the client.
|
||||||
/// The caller is responsible for generating the full response.
|
/// The caller is responsible for generating the full response.
|
||||||
/// Set the <see cref="AuthenticationTicket"/> to trigger SignIn.
|
/// Set the <see cref="Ticket"/> to trigger SignIn.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void HandleResponse()
|
public void HandleResponse()
|
||||||
{
|
{
|
||||||
|
|
@ -43,8 +43,8 @@ namespace Microsoft.AspNet.Authentication
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or set the <see cref="AuthenticationTicket"/> to return if this event signals it handled the event.
|
/// Gets or set the <see cref="Ticket"/> to return if this event signals it handled the event.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public AuthenticationTicket AuthenticationTicket { get; set; }
|
public AuthenticationTicket Ticket { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -16,7 +16,7 @@ namespace Microsoft.AspNet.Authentication
|
||||||
: base(context)
|
: base(context)
|
||||||
{
|
{
|
||||||
Options = options;
|
Options = options;
|
||||||
AuthenticationTicket = ticket;
|
Ticket = ticket;
|
||||||
if (ticket != null)
|
if (ticket != null)
|
||||||
{
|
{
|
||||||
Principal = ticket.Principal;
|
Principal = ticket.Principal;
|
||||||
|
|
|
||||||
|
|
@ -531,7 +531,7 @@ namespace Microsoft.AspNet.Authentication.Google
|
||||||
OnCreatingTicket = context =>
|
OnCreatingTicket = context =>
|
||||||
{
|
{
|
||||||
var refreshToken = context.RefreshToken;
|
var refreshToken = context.RefreshToken;
|
||||||
context.Principal.AddIdentity(new ClaimsIdentity(new Claim[] { new Claim("RefreshToken", refreshToken, ClaimValueTypes.String, "Google") }, "Google"));
|
context.Ticket.Principal.AddIdentity(new ClaimsIdentity(new Claim[] { new Claim("RefreshToken", refreshToken, ClaimValueTypes.String, "Google") }, "Google"));
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -610,7 +610,7 @@ namespace Microsoft.AspNet.Authentication.Google
|
||||||
{
|
{
|
||||||
OnTicketReceived = context =>
|
OnTicketReceived = context =>
|
||||||
{
|
{
|
||||||
context.AuthenticationTicket.Properties.RedirectUri = null;
|
context.Ticket.Properties.RedirectUri = null;
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
new Claim(ClaimsIdentity.DefaultNameClaimType, "bob")
|
new Claim(ClaimsIdentity.DefaultNameClaimType, "bob")
|
||||||
};
|
};
|
||||||
|
|
||||||
context.AuthenticationTicket = new AuthenticationTicket(
|
context.Ticket = new AuthenticationTicket(
|
||||||
new ClaimsPrincipal(new ClaimsIdentity(claims, context.Options.AuthenticationScheme)),
|
new ClaimsPrincipal(new ClaimsIdentity(claims, context.Options.AuthenticationScheme)),
|
||||||
new AuthenticationProperties(), context.Options.AuthenticationScheme);
|
new AuthenticationProperties(), context.Options.AuthenticationScheme);
|
||||||
|
|
||||||
|
|
@ -160,7 +160,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
new Claim(ClaimsIdentity.DefaultNameClaimType, "bob")
|
new Claim(ClaimsIdentity.DefaultNameClaimType, "bob")
|
||||||
};
|
};
|
||||||
|
|
||||||
context.AuthenticationTicket = new AuthenticationTicket(
|
context.Ticket = new AuthenticationTicket(
|
||||||
new ClaimsPrincipal(new ClaimsIdentity(claims, context.Options.AuthenticationScheme)),
|
new ClaimsPrincipal(new ClaimsIdentity(claims, context.Options.AuthenticationScheme)),
|
||||||
new AuthenticationProperties(), context.Options.AuthenticationScheme);
|
new AuthenticationProperties(), context.Options.AuthenticationScheme);
|
||||||
|
|
||||||
|
|
@ -189,7 +189,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
{
|
{
|
||||||
// Retrieve the NameIdentifier claim from the identity
|
// Retrieve the NameIdentifier claim from the identity
|
||||||
// returned by the custom security token validator.
|
// returned by the custom security token validator.
|
||||||
var identity = (ClaimsIdentity)context.AuthenticationTicket.Principal.Identity;
|
var identity = (ClaimsIdentity)context.Ticket.Principal.Identity;
|
||||||
var identifier = identity.FindFirst(ClaimTypes.NameIdentifier);
|
var identifier = identity.FindFirst(ClaimTypes.NameIdentifier);
|
||||||
|
|
||||||
Assert.Equal("Bob le Tout Puissant", identifier.Value);
|
Assert.Equal("Bob le Tout Puissant", identifier.Value);
|
||||||
|
|
@ -236,7 +236,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
new Claim(ClaimsIdentity.DefaultNameClaimType, "bob")
|
new Claim(ClaimsIdentity.DefaultNameClaimType, "bob")
|
||||||
};
|
};
|
||||||
|
|
||||||
context.AuthenticationTicket = new AuthenticationTicket(
|
context.Ticket = new AuthenticationTicket(
|
||||||
new ClaimsPrincipal(new ClaimsIdentity(claims, context.Options.AuthenticationScheme)),
|
new ClaimsPrincipal(new ClaimsIdentity(claims, context.Options.AuthenticationScheme)),
|
||||||
new AuthenticationProperties(), context.Options.AuthenticationScheme);
|
new AuthenticationProperties(), context.Options.AuthenticationScheme);
|
||||||
|
|
||||||
|
|
@ -268,7 +268,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
new Claim(ClaimsIdentity.DefaultNameClaimType, "bob")
|
new Claim(ClaimsIdentity.DefaultNameClaimType, "bob")
|
||||||
};
|
};
|
||||||
|
|
||||||
context.AuthenticationTicket = new AuthenticationTicket(
|
context.Ticket = new AuthenticationTicket(
|
||||||
new ClaimsPrincipal(new ClaimsIdentity(claims, context.Options.AuthenticationScheme)),
|
new ClaimsPrincipal(new ClaimsIdentity(claims, context.Options.AuthenticationScheme)),
|
||||||
new AuthenticationProperties(), context.Options.AuthenticationScheme);
|
new AuthenticationProperties(), context.Options.AuthenticationScheme);
|
||||||
|
|
||||||
|
|
@ -299,7 +299,7 @@ namespace Microsoft.AspNet.Authentication.JwtBearer
|
||||||
new Claim(ClaimsIdentity.DefaultNameClaimType, "bob")
|
new Claim(ClaimsIdentity.DefaultNameClaimType, "bob")
|
||||||
};
|
};
|
||||||
|
|
||||||
context.AuthenticationTicket = new AuthenticationTicket(
|
context.Ticket = new AuthenticationTicket(
|
||||||
new ClaimsPrincipal(new ClaimsIdentity(claims, context.Options.AuthenticationScheme)),
|
new ClaimsPrincipal(new ClaimsIdentity(claims, context.Options.AuthenticationScheme)),
|
||||||
new AuthenticationProperties(), context.Options.AuthenticationScheme);
|
new AuthenticationProperties(), context.Options.AuthenticationScheme);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -150,7 +150,7 @@ namespace Microsoft.AspNet.Authentication.Tests.MicrosoftAccount
|
||||||
OnCreatingTicket = context =>
|
OnCreatingTicket = context =>
|
||||||
{
|
{
|
||||||
var refreshToken = context.RefreshToken;
|
var refreshToken = context.RefreshToken;
|
||||||
context.Principal.AddIdentity(new ClaimsIdentity(new Claim[] { new Claim("RefreshToken", refreshToken, ClaimValueTypes.String, "Microsoft") }, "Microsoft"));
|
context.Ticket.Principal.AddIdentity(new ClaimsIdentity(new Claim[] { new Claim("RefreshToken", refreshToken, ClaimValueTypes.String, "Microsoft") }, "Microsoft"));
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue