Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
Added call to PrincipalCreated after authenticating with a refresh token
Browse files Browse the repository at this point in the history
  • Loading branch information
azzlack committed May 21, 2015
1 parent 874d0f9 commit f36037d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public class SentinelAuthorizationServerEvents
public Func<TokenIssuedEventArgs, Task> TokenIssued;

/// <summary>
/// Activated when the user is logged in and the principal is created. Use this event to add any
/// custom claims to the user before the token is created.
/// Activated when the user is logged in (either via a username and password, or a refresh token)
/// and the principal is created. Use this event to add any custom claims to the user before the
/// token is created.
/// </summary>
public Func<PrincipalCreatedEventArgs, Task> PrincipalCreated;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,19 @@ public override async Task GrantRefreshToken(OAuthGrantRefreshTokenContext conte
{
this.options.Logger.Debug("Authenticating refresh token flow");

context.Validated();
var user = new SentinelPrincipal(context.Ticket.Identity);

// Activate event if subscribed to
if (this.options.Events.PrincipalCreated != null)
{
var args = new PrincipalCreatedEventArgs(user, context);

await this.options.Events.PrincipalCreated(args);

user = new SentinelPrincipal(args.Principal);
}

context.Validated(user.Identity.AsClaimsIdentity());
}

/// <summary>Called before the TokenEndpoint redirects its response to the caller.</summary>
Expand Down

0 comments on commit f36037d

Please sign in to comment.