@@ -26,51 +26,63 @@ public static class ScriptJwtBearerExtensions
26
26
public static AuthenticationBuilder AddScriptJwtBearer ( this AuthenticationBuilder builder )
27
27
=> builder . AddJwtBearer ( o =>
28
28
{
29
- o . Events = new JwtBearerEvents ( )
30
- {
31
- OnMessageReceived = c =>
32
- {
33
- // By default, tokens are passed via the standard Authorization Bearer header. However we also support
34
- // passing tokens via the x-ms-site-token header.
35
- if ( c . Request . Headers . TryGetValue ( ScriptConstants . SiteTokenHeaderName , out StringValues values ) )
36
- {
37
- // the token we set here will be the one used - Authorization header won't be checked.
38
- c . Token = values . FirstOrDefault ( ) ;
39
- }
40
-
41
- // Temporary: Tactical fix to address specialization issues. This should likely be moved to a token validator
42
- // TODO: DI (FACAVAL) This will be fixed once the permanent fix is in place
43
- if ( _specialized == 0 && ! SystemEnvironment . Instance . IsPlaceholderModeEnabled ( ) && Interlocked . CompareExchange ( ref _specialized , 1 , 0 ) == 0 )
44
- {
45
- o . TokenValidationParameters = CreateTokenValidationParameters ( ) ;
46
- }
47
-
48
- return Task . CompletedTask ;
49
- } ,
50
- OnTokenValidated = c =>
51
- {
52
- c . Principal . AddIdentity ( new ClaimsIdentity ( new Claim [ ]
53
- {
54
- new Claim ( SecurityConstants . AuthLevelClaimType , AuthorizationLevel . Admin . ToString ( ) )
55
- } ) ) ;
56
-
57
- c . Success ( ) ;
58
-
59
- return Task . CompletedTask ;
60
- }
61
- } ;
62
-
29
+ o . Events = new JwtBearerEvents ( )
30
+ {
31
+ OnMessageReceived = c =>
32
+ {
33
+ // By default, tokens are passed via the standard Authorization Bearer header. However we also support
34
+ // passing tokens via the x-ms-site-token header.
35
+ if ( c . Request . Headers . TryGetValue ( ScriptConstants . SiteTokenHeaderName , out StringValues values ) )
36
+ {
37
+ // the token we set here will be the one used - Authorization header won't be checked.
38
+ c . Token = values . FirstOrDefault ( ) ;
39
+ }
40
+ // Temporary: Tactical fix to address specialization issues. This should likely be moved to a token validator
41
+ // TODO: DI (FACAVAL) This will be fixed once the permanent fix is in place
42
+ if ( _specialized == 0 && ! SystemEnvironment . Instance . IsPlaceholderModeEnabled ( ) && Interlocked . CompareExchange ( ref _specialized , 1 , 0 ) == 0 )
43
+ {
63
44
o . TokenValidationParameters = CreateTokenValidationParameters ( ) ;
45
+ }
46
+ return Task . CompletedTask ;
47
+ } ,
48
+ OnTokenValidated = c =>
49
+ {
50
+ c . Principal . AddIdentity ( new ClaimsIdentity ( new Claim [ ]
51
+ {
52
+ new Claim ( SecurityConstants . AuthLevelClaimType , AuthorizationLevel . Admin . ToString ( ) )
53
+ } ) ) ;
54
+ c . Success ( ) ;
55
+ return Task . CompletedTask ;
56
+ }
57
+ } ;
58
+ o . TokenValidationParameters = CreateTokenValidationParameters ( ) ;
59
+ // TODO: DI (FACAVAL) Remove this once the work above is completed.
60
+ if ( ! SystemEnvironment . Instance . IsPlaceholderModeEnabled ( ) )
61
+ {
62
+ // We're not in standby mode, so flag as specialized
63
+ _specialized = 1 ;
64
+ }
65
+ } ) ;
64
66
65
- // TODO: DI (FACAVAL) Remove this once the work above is completed.
66
- if ( ! SystemEnvironment . Instance . IsPlaceholderModeEnabled ( ) )
67
- {
68
- // We're not in standby mode, so flag as specialized
69
- _specialized = 1 ;
70
- }
71
- } ) ;
67
+ private static string [ ] GetValidAudiences ( )
68
+ {
69
+ if ( SystemEnvironment . Instance . IsPlaceholderModeEnabled ( )
70
+ && SystemEnvironment . Instance . IsLinuxConsumptionOnAtlas ( ) )
71
+ {
72
+ return new string [ ]
73
+ {
74
+ ScriptSettingsManager . Instance . GetSetting ( ContainerName )
75
+ } ;
76
+ }
72
77
73
- private static TokenValidationParameters CreateTokenValidationParameters ( )
78
+ return new string [ ]
79
+ {
80
+ string . Format ( SiteAzureFunctionsUriFormat , ScriptSettingsManager . Instance . GetSetting ( AzureWebsiteName ) ) ,
81
+ string . Format ( SiteUriFormat , ScriptSettingsManager . Instance . GetSetting ( AzureWebsiteName ) )
82
+ } ;
83
+ }
84
+
85
+ public static TokenValidationParameters CreateTokenValidationParameters ( )
74
86
{
75
87
var signingKeys = SecretsUtility . GetTokenIssuerSigningKeys ( ) ;
76
88
var result = new TokenValidationParameters ( ) ;
@@ -79,11 +91,7 @@ private static TokenValidationParameters CreateTokenValidationParameters()
79
91
result . IssuerSigningKeys = signingKeys ;
80
92
result . ValidateAudience = true ;
81
93
result . ValidateIssuer = true ;
82
- result . ValidAudiences = new string [ ]
83
- {
84
- string . Format ( SiteAzureFunctionsUriFormat , ScriptSettingsManager . Instance . GetSetting ( AzureWebsiteName ) ) ,
85
- string . Format ( SiteUriFormat , ScriptSettingsManager . Instance . GetSetting ( AzureWebsiteName ) )
86
- } ;
94
+ result . ValidAudiences = GetValidAudiences ( ) ;
87
95
result . ValidIssuers = new string [ ]
88
96
{
89
97
AppServiceCoreUri ,
0 commit comments