add tenant extraction on signIn
ef305049
Michael Schmitz
committed
succeeded
2 changed files
NativeAuthenticationStateProvider.cs
/WPE.App.Authentication.Maui/Business/NativeAuthenticationStateProvider.cs-2+10
/WPE.App.Authentication.Maui/Business/NativeAuthenticationStateProvider.cs
Add comment 12 namespace Infsoft.WPE.App.Authentication.Maui.Business
Add comment 13 {
Add comment 14 internal class NativeAuthenticationStateProvider(ITokenManager TokenManager, IAuthClient AuthClient, ISettingsProvider SettingsProvider,
Add comment 15 Minus   ILogger<NativeAuthenticationStateProvider> logger, IPlatformPreferenceService PlatformPreferenceService) : AppAuthenticationStateProvider(logger, PlatformPreferenceService)
Add comment 15 Plus   ILogger<NativeAuthenticationStateProvider> logger, IPlatformPreferenceService platformPreferenceService) : AppAuthenticationStateProvider(logger, platformPreferenceService)
Add comment 16 {
Add comment 17 public override async Task<AuthenticationState> GetAuthenticationStateAsync()
Add comment 18 {
Add comment 61 {
Add comment 62 var scope = SettingsProvider.ServerEnvironment is not AppEnvironment.Prod ? "env.test" : "env.prod";
Add comment 63 var authResult = await AuthClient.SignIn(loginType, scope, emailOrVoucherCode);
Add comment 64 Plus   var tenant = authResult.User.FindFirst(claim => claim.Type == "tenant");
Add comment 64 65
Add comment 65 Minus   if (authResult.IsError)
Add comment 66 Plus   if (authResult.IsError || tenant is null)
Add comment 66 67 return NoUser;
Add comment 67 68 else
Add comment 68 69 {
Add comment 69 70 await TokenManager.SetAllTokens(authResult.IdentityToken, authResult.AccessToken, authResult.RefreshToken, authResult.AccessTokenExpiration);
Add comment 71 Plus   PlatformPreferenceService.SetTenant(tenant.Value);
Add comment 70 72 return authResult.User;
Add comment 71 73 }
Add comment 72 74 }
Add comment 90 92 {
Add comment 91 93 if (await TokenManager.GetAccessToken() != null)
Add comment 92 94 await ExtractUser();
Add comment 95 Plus   var tenant = cachedUser.FindFirst(claim => claim.Type == "tenant");
Add comment 96 Plus   if (tenant is null)
Add comment 97 Plus   cachedUser = NoUser;
Add comment 98 Plus   else
Add comment 99 Plus   PlatformPreferenceService.SetTenant(tenant.Value);
Add comment 100 Plus  
Add comment 93 101 return new AuthenticationState(cachedUser);
Add comment 94 102 }
Add comment 95 103
WPE.App.Authentication.Maui.csproj
/WPE.App.Authentication.Maui/WPE.App.Authentication.Maui.csproj-2+2
/WPE.App.Authentication.Maui/WPE.App.Authentication.Maui.csproj
Add comment 24 <PackageIcon>icon.png</PackageIcon>
Add comment 25 <PackageReadmeFile>ReadMe.md</PackageReadmeFile>
Add comment 26 <PackageTags>WPE;Workplace Experience;infsoft</PackageTags>
Add comment 27 Minus   <Version>0.3.2</Version>
Add comment 27 Plus   <Version>0.3.3</Version>
Add comment 28 <GenerateDocumentationFile>true</GenerateDocumentationFile>
Add comment 29 </PropertyGroup>
Add comment 30
Add comment 31 <ItemGroup>
Add comment 32 Minus   <PackageReference Include="Infsoft.WPE.App.Authentication.Base" Version="0.4.7" />
Add comment 32 Plus   <PackageReference Include="Infsoft.WPE.App.Authentication.Base" Version="0.4.8" />
Add comment 33 <PackageReference Include="Infsoft.WPE.App.DTO" Version="1.5.0" />
Add comment 34 <PackageReference Include="IdentityModel.OidcClient" Version="6.0.0" />
Add comment 35 <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.6.0" />