@@ -35,6 +35,7 @@ public override ValueTask<AccessToken> GetTokenAsync(TokenRequestContext request
35
35
}
36
36
37
37
private const string AuthenticationRecordEnvVarName = "AZURE_MCP_AUTHENTICATION_RECORD" ;
38
+ private const string BrowserAuthenticationTimeoutEnvVarName = "AZURE_MCP_BROWSER_AUTH_TIMEOUT_SECONDS" ;
38
39
private const string OnlyUseBrokerCredentialEnvVarName = "AZURE_MCP_ONLY_USE_BROKER_CREDENTIAL" ;
39
40
private const string ClientIdEnvVarName = "AZURE_MCP_CLIENT_ID" ;
40
41
private const string IncludeProductionCredentialEnvVarName = "AZURE_MCP_INCLUDE_PRODUCTION_CREDENTIALS" ;
@@ -67,7 +68,7 @@ private static ChainedTokenCredential CreateChainedCredential(string? tenantId)
67
68
68
69
private static string TokenCacheName = "azure-mcp-msal.cache" ;
69
70
70
- private static InteractiveBrowserCredential CreateBrowserCredential ( string ? tenantId , AuthenticationRecord ? authRecord )
71
+ private static TokenCredential CreateBrowserCredential ( string ? tenantId , AuthenticationRecord ? authRecord )
71
72
{
72
73
string ? clientId = Environment . GetEnvironmentVariable ( ClientIdEnvVarName ) ;
73
74
@@ -89,7 +90,16 @@ private static InteractiveBrowserCredential CreateBrowserCredential(string? tena
89
90
brokerOptions . ClientId = clientId ;
90
91
}
91
92
92
- return new ( brokerOptions ) ;
93
+ var browserCredential = new InteractiveBrowserCredential ( brokerOptions ) ;
94
+
95
+ // Check for timeout value in the environment variable
96
+ string ? timeoutValue = Environment . GetEnvironmentVariable ( BrowserAuthenticationTimeoutEnvVarName ) ;
97
+ int timeoutSeconds = 300 ; // Default to 300 seconds (5 minutes)
98
+ if ( ! string . IsNullOrEmpty ( timeoutValue ) && int . TryParse ( timeoutValue , out int parsedTimeout ) && parsedTimeout > 0 )
99
+ {
100
+ timeoutSeconds = parsedTimeout ;
101
+ }
102
+ return new TimeoutTokenCredential ( browserCredential , TimeSpan . FromSeconds ( timeoutSeconds ) ) ;
93
103
}
94
104
95
105
private static DefaultAzureCredential CreateDefaultCredential ( string ? tenantId )
0 commit comments