Skip to content
This repository was archived by the owner on Dec 24, 2020. It is now read-only.

Commit ceee2fd

Browse files
committed
Add OAuthIntrospectionOptions.NameClaimType/RoleClaimType and replace the legacy WS-Fed claim types by their JWT equivalent
1 parent 4dc61f4 commit ceee2fd

6 files changed

Lines changed: 26 additions & 18 deletions

File tree

src/AspNet.Security.OAuth.Introspection/OAuthIntrospectionConstants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ public static class Claims
1515
public const string ExpiresAt = "exp";
1616
public const string IssuedAt = "iat";
1717
public const string JwtId = "jti";
18+
public const string Name = "name";
1819
public const string NotBefore = "nbf";
20+
public const string Role = "role";
1921
public const string Scope = "scope";
2022
public const string Subject = "sub";
2123
public const string TokenType = "token_type";

src/AspNet.Security.OAuth.Introspection/OAuthIntrospectionHandler.cs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ protected virtual bool ValidateAudience(AuthenticationTicket ticket)
435435

436436
protected virtual async Task<AuthenticationTicket> CreateTicketAsync(string token, JObject payload)
437437
{
438-
var identity = new ClaimsIdentity(Options.AuthenticationScheme);
438+
var identity = new ClaimsIdentity(Options.AuthenticationScheme, Options.NameClaimType, Options.RoleClaimType);
439439
var properties = new AuthenticationProperties();
440440

441441
if (Options.SaveToken)
@@ -483,22 +483,6 @@ protected virtual async Task<AuthenticationTicket> CreateTicketAsync(string toke
483483
continue;
484484
}
485485

486-
// Add the subject identifier as a new ClaimTypes.NameIdentifier claim.
487-
case OAuthIntrospectionConstants.Claims.Subject:
488-
{
489-
identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, (string) property.Value));
490-
491-
continue;
492-
}
493-
494-
// Add the subject identifier as a new ClaimTypes.Name claim.
495-
case OAuthIntrospectionConstants.Claims.Username:
496-
{
497-
identity.AddClaim(new Claim(ClaimTypes.Name, (string) property.Value));
498-
499-
continue;
500-
}
501-
502486
// Add the token identifier as a property on the authentication ticket.
503487
case OAuthIntrospectionConstants.Claims.JwtId:
504488
{

src/AspNet.Security.OAuth.Introspection/OAuthIntrospectionOptions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ public OAuthIntrospectionOptions()
9595
/// </summary>
9696
public bool IncludeErrorDetails { get; set; } = true;
9797

98+
/// <summary>
99+
/// Gets or sets the claim type used for the name claim.
100+
/// </summary>
101+
public string NameClaimType { get; set; } = OAuthIntrospectionConstants.Claims.Name;
102+
103+
/// <summary>
104+
/// Gets or sets the claim type used for the role claim(s).
105+
/// </summary>
106+
public string RoleClaimType { get; set; } = OAuthIntrospectionConstants.Claims.Role;
107+
98108
/// <summary>
99109
/// Gets or sets the cache used to store the authentication tickets
100110
/// resolved from the access tokens received by the resource server.

src/Owin.Security.OAuth.Introspection/OAuthIntrospectionConstants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ public static class Claims
1515
public const string ExpiresAt = "exp";
1616
public const string IssuedAt = "iat";
1717
public const string JwtId = "jti";
18+
public const string Name = "name";
1819
public const string NotBefore = "nbf";
20+
public const string Role = "role";
1921
public const string Scope = "scope";
2022
public const string Subject = "sub";
2123
public const string TokenType = "token_type";

src/Owin.Security.OAuth.Introspection/OAuthIntrospectionHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ protected virtual bool ValidateAudience(AuthenticationTicket ticket)
424424

425425
protected virtual async Task<AuthenticationTicket> CreateTicketAsync(string token, JObject payload)
426426
{
427-
var identity = new ClaimsIdentity(Options.AuthenticationType);
427+
var identity = new ClaimsIdentity(Options.AuthenticationType, Options.NameClaimType, Options.RoleClaimType);
428428
var properties = new AuthenticationProperties();
429429

430430
if (Options.SaveToken)

src/Owin.Security.OAuth.Introspection/OAuthIntrospectionOptions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ public OAuthIntrospectionOptions()
9494
/// </summary>
9595
public bool IncludeErrorDetails { get; set; } = true;
9696

97+
/// <summary>
98+
/// Gets or sets the claim type used for the name claim.
99+
/// </summary>
100+
public string NameClaimType { get; set; } = OAuthIntrospectionConstants.Claims.Name;
101+
102+
/// <summary>
103+
/// Gets or sets the claim type used for the role claim(s).
104+
/// </summary>
105+
public string RoleClaimType { get; set; } = OAuthIntrospectionConstants.Claims.Role;
106+
97107
/// <summary>
98108
/// Gets or sets the cache used to store the authentication tickets
99109
/// resolved from the access tokens received by the resource server.

0 commit comments

Comments
 (0)