File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ namespace GitHubConnector.Services;
2020/// <param name="settings">The application settings.</param>
2121public class M365AppConfigService ( AppSettings settings )
2222{
23+ private static readonly string GraphNotificationPublisherId = "0bf30f3b-4a52-48df-9a82-234910c4a086" ;
24+
2325 private readonly HttpListener listener = new ( ) ;
2426 private readonly int port = settings . PortNumber ;
2527 private readonly string tenantId = settings . TenantId ?? throw new ArgumentException ( "tenantId not set in app settings" ) ;
@@ -79,23 +81,31 @@ public async Task<bool> ValidateTokensAsync(List<string>? tokens)
7981 {
8082 try
8183 {
82- handler . ValidateToken (
84+ var principal = handler . ValidateToken (
8385 token ,
8486 new ( )
8587 {
8688 ValidateIssuer = true ,
8789 ValidateAudience = true ,
8890 ValidateIssuerSigningKey = true ,
8991 ValidateLifetime = true ,
90- ValidIssuers = new [ ]
91- {
92+ ValidIssuers =
93+ [
9294 $ "https://login.microsoftonline.com/{ tenantId } /v2.0",
9395 $ "https://sts.windows.net/{ tenantId } /",
94- } ,
96+ ] ,
9597 ValidAudience = clientId ,
9698 IssuerSigningKeys = openIdConfig . SigningKeys ,
9799 } ,
98100 out _ ) ;
101+
102+ var azpClaim = principal ? . FindFirst ( "azp" ) ;
103+ if ( azpClaim != null && string . Compare ( azpClaim . Value , GraphNotificationPublisherId , StringComparison . OrdinalIgnoreCase ) == 0 )
104+ {
105+ continue ;
106+ }
107+
108+ return false ;
99109 }
100110 catch ( SecurityTokenValidationException )
101111 {
You can’t perform that action at this time.
0 commit comments