4 changed files
WPE.App.Authentication.Maui | ||
Business | ||
Flow | ||
AuthClient.cs | ||
IAuthClient.cs | ||
NativeAuthenticationStateProvider.cs | ||
WPE.App.Authentication.Maui.csproj | ||
AuthClient.cs
/WPE.App.Authentication.Maui/Business/Flow/AuthClient.cs-9+8/WPE.App.Authentication.Maui/Business/Flow/AuthClient.cs
Add comment 3 using IdentityModel.OidcClient.Results;
Add comment 4 using Infsoft.WPE.App.Authentication.Base.Models;
Add comment 5 using Infsoft.WPE.App.Authentication.Maui.Models;
Add comment 6 Minus using Infsoft.WPE.App.Services.Models;
Add comment 7 6 using Infsoft.WPE.App.Services;
Add comment 8 7 using Microsoft.Extensions.Options;
Add comment 9 8 using IBrowser = IdentityModel.OidcClient.Browser.IBrowser;
Add comment 49 48 }
Add comment 50 49
Add comment 51 50 /// <inheritdoc/>
Add comment 52 Minus public async Task SignOut()
Add comment 53 Minus {
Add comment 54 Minus await OidcClient.LogoutAsync();
Add comment 55 Minus }
Add comment 51 Plus public Task SignOut() =>
Add comment 52 Plus OidcClient.LogoutAsync();
Add comment 53 Plus
Add comment 54 Plus /// <inheritdoc/>
Add comment 55 Plus public Task<UserInfoResult> GetUserInfo(string accessToken) =>
Add comment 56 Plus OidcClient.GetUserInfoAsync(accessToken);
Add comment 56 57
Add comment 57 58 /// <inheritdoc/>
Add comment 58 Minus public async Task<RefreshTokenResult> RefreshTokens(string refreshToken)
Add comment 59 Minus {
Add comment 60 Minus return await OidcClient.RefreshTokenAsync(refreshToken, scope: OidcClient.Options.Scope);
Add comment 61 Minus }
Add comment 59 Plus public Task<RefreshTokenResult> RefreshTokens(string refreshToken) =>
Add comment 60 Plus OidcClient.RefreshTokenAsync(refreshToken, scope: OidcClient.Options.Scope);
Add comment 62 61
Add comment 63 62 private OidcClient CreateOidcClient(LoginType loginType, string emailOrVoucherCode)
Add comment 64 63 {
IAuthClient.cs
/WPE.App.Authentication.Maui/Business/Flow/IAuthClient.cs+11/WPE.App.Authentication.Maui/Business/Flow/IAuthClient.cs
Add comment 25 /// <param name="refreshToken">Token to authenticate refresh</param>
Add comment 26 /// <returns>Result of token refresh, contains all tokens if successfull</returns>
Add comment 27 Task<RefreshTokenResult> RefreshTokens(string refreshToken);
Add comment 28 Plus
Add comment 29 Plus /// <summary>
Add comment 30 Plus /// Signout the user on the IdP
Add comment 31 Plus /// </summary>
Add comment 28 32 Task SignOut();
Add comment 33 Plus
Add comment 34 Plus /// <summary>
Add comment 35 Plus /// Query userInfo of IdP
Add comment 36 Plus /// </summary>
Add comment 37 Plus /// <param name="accessToken">Token to authenticate api call</param>
Add comment 38 Plus /// <returns>user information as per userInfo endpoint</returns>
Add comment 39 Plus Task<UserInfoResult> GetUserInfo(string accessToken);
Add comment 29 40 }
Add comment 30 41 }
NativeAuthenticationStateProvider.cs
/WPE.App.Authentication.Maui/Business/NativeAuthenticationStateProvider.cs-10+14/WPE.App.Authentication.Maui/Business/NativeAuthenticationStateProvider.cs
Add comment 1 Minus using IdentityModel;
Add comment 2 1 using Infsoft.WPE.App.Authentication.Base.Business;
Add comment 3 2 using Infsoft.WPE.App.Authentication.Base.Models;
Add comment 4 3 using Infsoft.WPE.App.Authentication.Maui.Business.Flow;
Add comment 5 4 using Infsoft.WPE.App.Authentication.Maui.Business.Token;
Add comment 6 Minus using Infsoft.WPE.App.DTO;
Add comment 7 Minus using Infsoft.WPE.App.Extensions;
Add comment 8 5 using Infsoft.WPE.App.Services;
Add comment 9 6 using Microsoft.AspNetCore.Components.Authorization;
Add comment 10 7 using Microsoft.Extensions.Logging;
Add comment 11 Minus using System.IdentityModel.Tokens.Jwt;
Add comment 12 8 using System.Security.Claims;
Add comment 13 9
Add comment 14 10 namespace Infsoft.WPE.App.Authentication.Maui.Business
Add comment 15 11 {
Add comment 16 Minus internal class NativeAuthenticationStateProvider(ITokenManager TokenManager, IAuthClient AuthClient, ISettingsProvider SettingsProvider,
Add comment 12 Plus internal class NativeAuthenticationStateProvider(ITokenManager TokenManager, IAuthClient AuthClient,
Add comment 17 13 ILogger<NativeAuthenticationStateProvider> logger, IPlatformPreferenceService platformPreferenceService) : AppAuthenticationStateProvider(logger, platformPreferenceService)
Add comment 18 14 {
Add comment 19 15 public override async Task<AuthenticationState> GetAuthenticationStateAsync()
Add comment 93 89 private async Task<AuthenticationState> SilentSignInCore()
Add comment 94 90 {
Add comment 95 91 if (await TokenManager.GetAccessToken() != null)
Add comment 96 Minus await ExtractUser();
Add comment 92 Plus cachedUser = await ExtractUser();
Add comment 97 93 var tenant = cachedUser.FindFirst(claim => claim.Type == "tenant");
Add comment 98 94 if (tenant is null)
Add comment 95 Plus {
Add comment 96 Plus Logger.LogDebug("No tenant detected");
Add comment 99 97 cachedUser = NoUser;
Add comment 98 Plus }
Add comment 100 99 else
Add comment 101 100 PlatformPreferenceService.SetTenant(tenant.Value);
Add comment 102 101
Add comment 126 125
Add comment 127 126 private async Task<ClaimsPrincipal> ExtractUser()
Add comment 128 127 {
Add comment 129 Minus Logger.LogInformation("Reading user information from id token");
Add comment 130 Minus var token = await TokenManager.GetIdToken();
Add comment 128 Plus Logger.LogInformation("Querying user information from userInfo endpoint");
Add comment 129 Plus var token = await TokenManager.GetAccessToken();
Add comment 131 130 if (token is null)
Add comment 132 131 return NoUser;
Add comment 133 132
Add comment 134 Minus var parsed = new JwtSecurityTokenHandler().ReadJwtToken(token);
Add comment 133 Plus var profile = await AuthClient.GetUserInfo(token);
Add comment 134 Plus if (profile.IsError)
Add comment 135 Plus {
Add comment 136 Plus Logger.LogDebug("Error on fetching profile information: {Error}, {Description}", profile.Error, profile.ErrorDescription);
Add comment 137 Plus return NoUser;
Add comment 138 Plus }
Add comment 135 139 var identity = new ClaimsIdentity(
Add comment 136 140 nameof(NativeAuthenticationStateProvider),
Add comment 137 141 "name",
Add comment 138 142 "role");
Add comment 139 143
Add comment 140 Minus identity.AddClaims(parsed.Claims);
Add comment 144 Plus identity.AddClaims(profile.Claims);
Add comment 141 145
Add comment 142 146 return new ClaimsPrincipal(identity);
Add comment 143 147 }
WPE.App.Authentication.Maui.csproj
/WPE.App.Authentication.Maui/WPE.App.Authentication.Maui.csproj-1+1/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.8</Version>
Add comment 27 Plus <Version>0.3.9</Version>
Add comment 28 <GenerateDocumentationFile>true</GenerateDocumentationFile>
Add comment 29 </PropertyGroup>
Add comment 30