@@ -78,24 +78,7 @@ public static EnvironmentConfiguration AddEnvironmentConfiguration(
7878 new TokenRequestContext ( [ "https://graph.microsoft.com/.default" ] ) ,
7979 CancellationToken . None ) ;
8080
81- // Should be UPN, but guest accounts does not have UPN, so we use email instead.
82- var webToken = new JsonWebToken ( accessToken . Token ) ;
83- string developerInitials ;
84-
85- if ( webToken . TryGetPayloadValue ( "upn" , out string upn ) )
86- {
87- developerInitials = upn . Split ( '@' ) . FirstOrDefault ( ) ??
88- throw new ArgumentException ( $ "Invalid developer upn { upn } ", upn ) ;
89- }
90- else if ( webToken . TryGetPayloadValue ( "email" , out string email ) )
91- {
92- developerInitials = email . Split ( '@' ) . FirstOrDefault ( ) ??
93- throw new ArgumentException ( $ "Invalid developer email { email } ", email ) ;
94- }
95- else
96- {
97- throw new InvalidOperationException ( "JWT token does not contain either UPN or email..." ) ;
98- }
81+ var developerInitials = ExtractDeveloperInitials ( accessToken ) ;
9982
10083 environmentConfiguration = environmentConfiguration with { ApplicationEnvironment = developerInitials } ;
10184 }
@@ -109,6 +92,30 @@ public static EnvironmentConfiguration AddEnvironmentConfiguration(
10992 return environmentConfiguration ;
11093 }
11194
95+ private static string ExtractDeveloperInitials ( AccessToken accessToken )
96+ {
97+ // Should be UPN, but guest accounts does not have UPN, so we use email instead.
98+ var webToken = new JsonWebToken ( accessToken . Token ) ;
99+ string developerInitials ;
100+
101+ if ( webToken . TryGetPayloadValue ( "upn" , out string upn ) )
102+ {
103+ developerInitials = upn . Split ( '@' ) . FirstOrDefault ( ) ??
104+ throw new ArgumentException ( $ "Invalid developer upn { upn } ", upn ) ;
105+ }
106+ else if ( webToken . TryGetPayloadValue ( "email" , out string email ) )
107+ {
108+ developerInitials = email . Split ( '@' ) . FirstOrDefault ( ) ??
109+ throw new ArgumentException ( $ "Invalid developer email { email } ", email ) ;
110+ }
111+ else
112+ {
113+ throw new InvalidOperationException ( "JWT token does not contain either UPN or email..." ) ;
114+ }
115+
116+ return developerInitials ;
117+ }
118+
112119 private static EnvironmentConfiguration GetEnvironmentConfiguration (
113120 ConfigurationManager configuration ,
114121 string applicationName ,
0 commit comments