File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -79,9 +79,24 @@ public static EnvironmentConfiguration AddEnvironmentConfiguration(
7979 CancellationToken . None ) ;
8080
8181 // Should be UPN, but guest accounts does not have UPN, so we use email instead.
82- var developerUpn = new JsonWebToken ( accessToken . Token ) . GetPayloadValue < string > ( "email" ) ;
83- var developerInitials = developerUpn . Split ( '@' ) . FirstOrDefault ( ) ??
84- throw new ArgumentException ( $ "Invalid developer upn { developerUpn } ", developerUpn ) ;
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+ }
99+
85100 environmentConfiguration = environmentConfiguration with { ApplicationEnvironment = developerInitials } ;
86101 }
87102
You can’t perform that action at this time.
0 commit comments