@@ -46,7 +46,7 @@ public AuthenticateResult AuthUser(HttpContext context, ProviderOptions? options
4646 this . defaultOptions . ChangeModel ( options ) ;
4747
4848 var tokenJson = this . GetTokenJson ( context . Request . Headers [ AuthorizationHeader ] . FirstOrDefault ( ) ) ;
49- var claims = this . BuildFromApplicationAuth ( tokenJson , this . defaultOptions ) ;
49+ var claims = this . BuildFromAuthToken ( tokenJson , this . defaultOptions ) ;
5050 var identityProviderClaim = tokenJson [ IdentityProviderKey ] ? . ToString ( ) ;
5151 if ( identityProviderClaim == null )
5252 {
@@ -68,7 +68,7 @@ public bool CanHandleAuthentification(HttpContext httpContext) =>
6868 IsHeaderSet ( httpContext . Request . Headers , AuthorizationHeader ) &&
6969 httpContext . Request . Headers [ AuthorizationHeader ] . FirstOrDefault ( ) . Contains ( JWTIdentifier ) ;
7070
71- private IEnumerable < AADClaimsModel > BuildFromApplicationAuth ( JObject xMsClientPrincipal , ProviderOptions options )
71+ private IEnumerable < AADClaimsModel > BuildFromAuthToken ( JObject xMsClientPrincipal , ProviderOptions options )
7272 {
7373 this . logger . LogDebug ( $ "payload was { xMsClientPrincipal [ this . defaultOptions . RoleClaimType ] . ToString ( ) } ") ;
7474
@@ -80,7 +80,13 @@ private IEnumerable<AADClaimsModel> BuildFromApplicationAuth(JObject xMsClientPr
8080 . Select ( claimToken => new AADClaimsModel { Typ = claimToken . Name , Values = claimToken . Value . ToString ( ) } )
8181 . ToList ( ) ;
8282 claims . AddRange ( otherClaims ) ;
83- claims . Add ( new AADClaimsModel { Typ = options . NameClaimType , Values = xMsClientPrincipal [ "appid" ] . ToString ( ) } ) ;
83+ claims . Add ( new AADClaimsModel
84+ {
85+ Typ = options . NameClaimType ,
86+ Values = xMsClientPrincipal . ContainsKey ( "upn" ) ?
87+ xMsClientPrincipal [ "upn" ] . ToString ( ) : // this appends if an user is using the auth token from the /.auth/me site on the website
88+ xMsClientPrincipal [ "appid" ] . ToString ( ) // this appends if an applicaiton is try accessing the app.
89+ } ) ;
8490 return claims ;
8591 }
8692
0 commit comments