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

Commit f36037d

Browse files
committed
Added call to PrincipalCreated after authenticating with a refresh token
1 parent 874d0f9 commit f36037d

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/Sentinel.OAuth.Core/Models/SentinelAuthorizationServerEvents.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ public class SentinelAuthorizationServerEvents
1414
public Func<TokenIssuedEventArgs, Task> TokenIssued;
1515

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

src/Sentinel.OAuth/Providers/OAuth/SentinelAuthorizationServerProvider.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,19 @@ public override async Task GrantRefreshToken(OAuthGrantRefreshTokenContext conte
345345
{
346346
this.options.Logger.Debug("Authenticating refresh token flow");
347347

348-
context.Validated();
348+
var user = new SentinelPrincipal(context.Ticket.Identity);
349+
350+
// Activate event if subscribed to
351+
if (this.options.Events.PrincipalCreated != null)
352+
{
353+
var args = new PrincipalCreatedEventArgs(user, context);
354+
355+
await this.options.Events.PrincipalCreated(args);
356+
357+
user = new SentinelPrincipal(args.Principal);
358+
}
359+
360+
context.Validated(user.Identity.AsClaimsIdentity());
349361
}
350362

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

0 commit comments

Comments
 (0)