Skip to content

Commit 3ddf25e

Browse files
author
robertob
committed
removing dead code associated with GenericIdentity/Principal in lieu of new ClaimsIdentity/Principal code that allows IsInRole() checks to work
1 parent 12508c0 commit 3ddf25e

1 file changed

Lines changed: 2 additions & 12 deletions

File tree

src/KK.AspNetCore.EasyAuthAuthentication/EasyAuthAuthenticationHandler.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ private AuthenticationTicket BuildIdentityFromEasyAuthRequestHeaders(Microsoft.A
9393
var name = requestHeaders["X-MS-CLIENT-PRINCIPAL-NAME"][0];
9494
this.Logger.LogDebug("payload was fetched from easyauth headers, name: {0}", name);
9595

96-
//var identity = new GenericIdentity(name, "AuthenticationTypes.Federation"); // setting ClaimsIdentity.AuthenticationType to value that azuread non-easyauth setups use
97-
9896
this.Logger.LogInformation("building claims from payload...");
9997

10098
var xMsClientPrincipal = JObject.Parse(Encoding.UTF8.GetString(Convert.FromBase64String(requestHeaders["X-MS-CLIENT-PRINCIPAL"][0])));
@@ -124,16 +122,13 @@ private AuthenticationTicket BuildIdentityFromEasyAuthRequestHeaders(Microsoft.A
124122
}
125123
}
126124

127-
this.Logger.LogInformation("Add claims to new identity");
128-
129-
//identity.AddClaims(claims);
125+
this.Logger.LogInformation("building new identity from claims");
130126
var identity = new ClaimsIdentity(claims, "AuthenticationTypes.Federation"); // setting ClaimsIdentity.AuthenticationType to value that azuread non-easyauth setups use
131127

132128
//identity.AddClaim(new Claim("id_token", idToken)); // don't think we should be including this
133129
//identity.AddClaim(new Claim("http://schemas.microsoft.com/claims/authnclassreference", 1)); // don't think we need to add this
134130
if (!(identity.Claims as List<Claim>).Exists(claim => claim.Type == "scp")) identity.AddClaim(new Claim("scp", "user_impersonation")); // not sure why easyauth is dropping this
135131
identity.AddClaim(new Claim("provider_name", requestHeaders["X-MS-CLIENT-PRINCIPAL-IDP"][0]));
136-
//var principal = new GenericPrincipal(identity, null); // maybe passing valid string[] roles for second parameter would make IsInRole work but no need just use ClaimsPrincipal
137132
var principal = new ClaimsPrincipal(identity);
138133
return new AuthenticationTicket(principal, EasyAuthAuthenticationDefaults.AuthenticationScheme);
139134
}
@@ -143,8 +138,6 @@ private AuthenticationTicket BuildIdentityFromEasyAuthMeJson(JObject payload)
143138
var name = payload["user_id"].Value<string>(); // X-MS-CLIENT-PRINCIPAL-NAME
144139
this.Logger.LogDebug("payload was fetched from easyauth me json, name: {0}", name);
145140

146-
//var identity = new GenericIdentity(name, "AuthenticationTypes.Federation"); // setting ClaimsIdentity.AuthenticationType to value that azuread non-easyauth setups use
147-
148141
this.Logger.LogInformation("building claims from payload...");
149142

150143
var claims = new List<Claim>();
@@ -172,16 +165,13 @@ private AuthenticationTicket BuildIdentityFromEasyAuthMeJson(JObject payload)
172165
}
173166
}
174167

175-
this.Logger.LogInformation("Add claims to new identity");
176-
177-
//identity.AddClaims(claims);
168+
this.Logger.LogInformation("building new identity from claims");
178169
var identity = new ClaimsIdentity(claims, "AuthenticationTypes.Federation"); // setting ClaimsIdentity.AuthenticationType to value that azuread non-easyauth setups use
179170

180171
//identity.AddClaim(new Claim("id_token", idToken)); // don't think we should be including this
181172
//identity.AddClaim(new Claim("http://schemas.microsoft.com/claims/authnclassreference", 1)); // don't think we need to add this
182173
if (!(identity.Claims as List<Claim>).Exists(claim => claim.Type == "scp")) identity.AddClaim(new Claim("scp", "user_impersonation")); // not sure why easyauth is dropping this
183174
identity.AddClaim(new Claim("provider_name", payload["provider_name"].Value<string>())); // X-MS-CLIENT-PRINCIPAL-IDP
184-
//var principal = new GenericPrincipal(identity, null); // maybe passing valid string[] roles for second parameter would make IsInRole work but no need just use ClaimsPrincipal
185175
var principal = new ClaimsPrincipal(identity);
186176
return new AuthenticationTicket(principal, EasyAuthAuthenticationDefaults.AuthenticationScheme);
187177
}

0 commit comments

Comments
 (0)