@@ -8,8 +8,8 @@ namespace UvA.Workflow.Api.Authentication;
88
99public class SurfConextAuthenticationHandler : AuthenticationHandler < SurfConextOptions >
1010{
11- private const string SURFCONEXT_ERROR = "SurfConextError" ;
12- public static string Scheme => "SURFconext" ;
11+ private const string SurfconextError = "SurfConextError" ;
12+ public static string SchemeName => "SURFconext" ;
1313
1414 /// <summary>
1515 /// implements the behavior of the SurfConext scheme to authenticate users.
@@ -56,7 +56,7 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
5656 var cacheKey = $ "bt_{ bearerToken } ";
5757
5858 if ( cache . TryGetValue ( cacheKey , out ClaimsPrincipal ? cachedPrincipal ) )
59- return AuthenticateResult . Success ( new AuthenticationTicket ( cachedPrincipal ! , Scheme ) ) ;
59+ return AuthenticateResult . Success ( new AuthenticationTicket ( cachedPrincipal ! , SchemeName ) ) ;
6060
6161 var resp = await ValidateSurfBearerToken ( bearerToken ) ;
6262 if ( resp == null )
@@ -81,7 +81,7 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
8181
8282 await userService . AddOrUpdateUser ( principal . Identity ! . Name ! , resp . FullName , resp . Email ) ;
8383
84- return AuthenticateResult . Success ( new AuthenticationTicket ( principal , Scheme ) ) ;
84+ return AuthenticateResult . Success ( new AuthenticationTicket ( principal , SchemeName ) ) ;
8585 }
8686
8787 protected override Task HandleChallengeAsync ( AuthenticationProperties properties )
@@ -91,7 +91,7 @@ protected override Task HandleChallengeAsync(AuthenticationProperties properties
9191 {
9292 Status = StatusCodes . Status401Unauthorized ,
9393 Title = "Unauthorized" ,
94- Detail = Context . Items [ SURFCONEXT_ERROR ] as string ?? "Unauthorized" ,
94+ Detail = Context . Items [ SurfconextError ] as string ?? "Unauthorized" ,
9595 Instance = Context . Request . Path . Value
9696 } ,
9797 new JsonSerializerOptions ( JsonSerializerDefaults . Web ) ) ;
@@ -112,7 +112,7 @@ protected override Task HandleChallengeAsync(AuthenticationProperties properties
112112 "Token validation failed: SurfConext returned status {Code}: {Response}, ClientId:{ClientId}, Secret:{ClientSecret}" ,
113113 response . StatusCode , content , OptionsMonitor . CurrentValue . ClientId ,
114114 OptionsMonitor . CurrentValue . ClientSecret ? [ ..4 ] ) ;
115- Context . Items [ SURFCONEXT_ERROR ] =
115+ Context . Items [ SurfconextError ] =
116116 $ "Token validation failed: SurfConext returned status { response . StatusCode } , check the logs for details";
117117 return null ;
118118 }
@@ -124,7 +124,7 @@ protected override Task HandleChallengeAsync(AuthenticationProperties properties
124124 catch ( Exception ex )
125125 {
126126 Logger . LogError ( ex , "Token validation failed: unable to deserialize response: {Response}" , content ) ;
127- Context . Items [ SURFCONEXT_ERROR ] =
127+ Context . Items [ SurfconextError ] =
128128 $ "Token validation failed: unable to deserialize response from SurfConext, check the logs for details";
129129 return null ;
130130 }
@@ -148,7 +148,7 @@ private static ClaimsPrincipal CreateClaimsPrincipal(IntrospectionResponse r)
148148
149149 if ( r . Uids is { Length : > 0 } && ! string . IsNullOrWhiteSpace ( r . Uids [ 0 ] ) )
150150 {
151- claims . Add ( new Claim ( ClaimTypes . NameIdentifier , r . Uids [ 0 ] ) ) ;
151+ claims . Add ( new Claim ( ClaimTypes . NameIdentifier , UvaClaimTypes . UvanetId ) ) ;
152152 claims . Add ( new Claim ( UvaClaimTypes . UvanetId , r . Uids [ 0 ] ) ) ;
153153 }
154154
@@ -177,7 +177,7 @@ private static ClaimsPrincipal CreateClaimsPrincipal(IntrospectionResponse r)
177177 claims . Add ( new Claim ( "updated_at" ,
178178 r . UpdatedAt . Value . ToString ( System . Globalization . CultureInfo . InvariantCulture ) ) ) ;
179179
180- var identity = new ClaimsIdentity ( claims , Scheme , UvaClaimTypes . UvanetId , ClaimTypes . Role ) ;
180+ var identity = new ClaimsIdentity ( claims , SchemeName , UvaClaimTypes . UvanetId , ClaimTypes . Role ) ;
181181 return new ClaimsPrincipal ( identity ) ;
182182 }
183183}
0 commit comments