Skip to content

Commit

Permalink
feat(deps): update projects dependencies #9282 (#9283)
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmoradi authored Nov 18, 2024
1 parent 502ec46 commit 87e0d6a
Show file tree
Hide file tree
Showing 39 changed files with 114 additions and 109 deletions.
4 changes: 2 additions & 2 deletions src/BlazorUI/Bit.BlazorUI.Assets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/BlazorUI/Bit.BlazorUI.Assets/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"devDependencies": {
"sass": "1.80.5"
"sass": "1.81.0"
}
}
4 changes: 2 additions & 2 deletions src/BlazorUI/Bit.BlazorUI.Extras/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/BlazorUI/Bit.BlazorUI.Extras/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"devDependencies": {
"esbuild": "0.24.0",
"sass": "1.80.5",
"sass": "1.81.0",
"typescript": "5.6.3"
}
}
4 changes: 2 additions & 2 deletions src/BlazorUI/Bit.BlazorUI.Icons/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/BlazorUI/Bit.BlazorUI.Icons/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"devDependencies": {
"sass": "1.80.5"
"sass": "1.81.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>12.0</LangVersion>
<LangVersion>13.0</LangVersion>
<Nullable>enable</Nullable>
<IsRoslynComponent>true</IsRoslynComponent>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorUI/Bit.BlazorUI.Tests/Bit.BlazorUI.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFrameworks>net9.0;net8.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<LangVersion>11.0</LangVersion>
<LangVersion>13.0</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/BlazorUI/Bit.BlazorUI/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/BlazorUI/Bit.BlazorUI/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"devDependencies": {
"esbuild": "0.24.0",
"sass": "1.80.5",
"sass": "1.81.0",
"typescript": "5.6.3"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"devDependencies": {
"esbuild": "0.24.0",
"sass": "1.80.5",
"sass": "1.81.0",
"typescript": "5.6.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Wpf" Version="9.0.10" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2849.39" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2903.40" />
<PackageReference Include="Velopack" Version="0.0.942" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />

Expand Down
2 changes: 1 addition & 1 deletion src/BlazorUI/Demo/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- Generated by bit-bp template v-9.0.0 -->
<Project>
<PropertyGroup>
<LangVersion>12.0</LangVersion>
<LangVersion>13.0</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ private async Task ConnectSignalR()
// WebSockets should be enabled on services like IIS or Cloudflare CDN, offering significantly better performance.
options.AccessTokenProvider = async () =>
{
var access_token = await AuthTokenProvider.GetAccessToken();
var accessToken = await AuthTokenProvider.GetAccessToken();

if (string.IsNullOrEmpty(access_token) is false &&
AuthTokenProvider.ParseAccessToken(access_token, validateExpiry: true).IsAuthenticated() is false)
if (string.IsNullOrEmpty(accessToken) is false &&
AuthTokenProvider.ParseAccessToken(accessToken, validateExpiry: true).IsAuthenticated() is false)
{
return await AuthenticationManager.RefreshToken(requestedBy: nameof(HubConnectionBuilder), CurrentCancellationToken);
return await AuthenticationManager.TryRefreshToken(requestedBy: nameof(HubConnectionBuilder), CurrentCancellationToken);
}

return access_token;
return accessToken;
};
})
.Build();
Expand Down Expand Up @@ -226,7 +226,7 @@ private async Task HubConnectionDisconnected(Exception? exception)

if (exception is HubException && exception.Message.EndsWith(nameof(AppStrings.UnauthorizedException)))
{
await AuthenticationManager.RefreshToken(requestedBy: nameof(HubException), CurrentCancellationToken);
await AuthenticationManager.TryRefreshToken(requestedBy: nameof(HubException), CurrentCancellationToken);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected override async Task OnInitializedAsync()

unsubscribers.Add(pubSubService.Subscribe(ClientPubSubMessages.IS_ONLINE_CHANGED, async payload =>
{
telemetryContext.IsOnline = isOnline;
telemetryContext.IsOnline = isOnline = (bool?)payload;
await InvokeAsync(StateHasChanged);
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ protected override async Task OnInitAsync()

user = (await PrerenderStateService.GetValue(() => HttpClient.GetFromJsonAsync("api/User/GetCurrentUser", JsonSerializerOptions.GetTypeInfo<UserDto>(), CurrentCancellationToken)))!;

var access_token = await PrerenderStateService.GetValue(AuthTokenProvider.GetAccessToken);
profileImageUrl = new Uri(AbsoluteServerAddress, $"/api/Attachment/GetProfileImage?access_token={access_token}").ToString();
var accessToken = await PrerenderStateService.GetValue(AuthTokenProvider.GetAccessToken);
profileImageUrl = new Uri(AbsoluteServerAddress, $"/api/Attachment/GetProfileImage?access_token={accessToken}").ToString();

await base.OnInitAsync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public partial class ProfileSection

protected override async Task OnInitAsync()
{
var access_token = await PrerenderStateService.GetValue(AuthTokenProvider.GetAccessToken);
var accessToken = await PrerenderStateService.GetValue(AuthTokenProvider.GetAccessToken);

removeProfileImageHttpUrl = $"api/Attachment/RemoveProfileImage?access_token={access_token}";
removeProfileImageHttpUrl = $"api/Attachment/RemoveProfileImage?access_token={accessToken}";

profileImageUrl = new Uri(AbsoluteServerAddress, $"/api/Attachment/GetProfileImage?access_token={access_token}").ToString();
profileImageUploadUrl = new Uri(AbsoluteServerAddress, $"/api/Attachment/UploadProfileImage?access_token={access_token}").ToString();
profileImageUrl = new Uri(AbsoluteServerAddress, $"/api/Attachment/GetProfileImage?access_token={accessToken}").ToString();
profileImageUploadUrl = new Uri(AbsoluteServerAddress, $"/api/Attachment/UploadProfileImage?access_token={accessToken}").ToString();

await base.OnInitAsync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ protected override async Task OnInitAsync()
{
user = await userController.GetCurrentUser(CurrentCancellationToken);

var access_token = await PrerenderStateService.GetValue(AuthTokenProvider.GetAccessToken);
profileImageUrl = new Uri(AbsoluteServerAddress, $"/api/Attachment/GetProfileImage?access_token={access_token}").ToString();
var accessToken = await PrerenderStateService.GetValue(AuthTokenProvider.GetAccessToken);
profileImageUrl = new Uri(AbsoluteServerAddress, $"/api/Attachment/GetProfileImage?access_token={accessToken}").ToString();
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ protected override async Task OnParamsSetAsync()

protected override async Task OnAfterFirstRenderAsync()
{
var refresh_token = await StorageService.GetItem("refresh_token");
var refreshToken = await StorageService.GetItem("refresh_token");

// Let's update the access token by refreshing it when a refresh token is available.
// Following this procedure, the newly acquired access token may now include the necessary roles or claims.
// To prevent infinities redirect loop, let's append try_refreshing_token=false to the url, so we only redirect in case no try_refreshing_token=false is present

if (string.IsNullOrEmpty(refresh_token) is false && ReturnUrl?.Contains("try_refreshing_token=false", StringComparison.InvariantCulture) is null or false)
if (string.IsNullOrEmpty(refreshToken) is false && ReturnUrl?.Contains("try_refreshing_token=false", StringComparison.InvariantCulture) is null or false)
{
isRefreshingToken = true;
StateHasChanged();
try
{
var access_token = await AuthenticationManager.RefreshToken(requestedBy: nameof(NotAuthorizedPage), CurrentCancellationToken);
if (string.IsNullOrEmpty(access_token) is false && ReturnUrl is not null)
var accessToken = await AuthenticationManager.TryRefreshToken(requestedBy: nameof(NotAuthorizedPage), CurrentCancellationToken);
if (string.IsNullOrEmpty(accessToken) is false && ReturnUrl is not null)
{
var @char = ReturnUrl.Contains('?') ? '&' : '?'; // The RedirectUrl may already include a query string.
NavigationManager.NavigateTo($"{ReturnUrl}{@char}try_refreshing_token=false", replace: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,39 +79,48 @@ public async Task SignOut(CancellationToken cancellationToken)
}
}

public async Task<string?> RefreshToken(string requestedBy, CancellationToken cancellationToken)
public async Task<string?> TryRefreshToken(string requestedBy, CancellationToken cancellationToken)
{
try
{
var access_token_BeforeLockValue = await tokenProvider.GetAccessToken();
return await RefreshToken(requestedBy, cancellationToken);
}
catch (Exception exp)
{
exceptionHandler.Handle(exp, new()
{
{ "AdditionalData", "Refreshing access token failed." },
{ "RefreshTokenRequestedBy", requestedBy }
});
return null;
}
}

public async Task<string> RefreshToken(string requestedBy, CancellationToken cancellationToken)
{
try
{
var accessTokenBeforeLock = await tokenProvider.GetAccessToken();
await semaphore.WaitAsync();
var access_token_AfterLockValue = await tokenProvider.GetAccessToken();
if (access_token_BeforeLockValue != access_token_AfterLockValue)
return access_token_AfterLockValue; // It was renewed by a concurrent refresh token request.
var accessTokenAfterLock = await tokenProvider.GetAccessToken();
if (accessTokenBeforeLock != accessTokenAfterLock)
return accessTokenAfterLock!; // It was renewed by a concurrent refresh token request.
authLogger.LogInformation("Refreshing access token requested by {RequestedBy}", requestedBy);
try
{
string? refresh_token = await storageService.GetItem("refresh_token");
if (string.IsNullOrEmpty(refresh_token))
string? refreshToken = await storageService.GetItem("refresh_token");
if (string.IsNullOrEmpty(refreshToken))
throw new UnauthorizedException(localizer[nameof(AppStrings.YouNeedToSignIn)]);

var refreshTokenResponse = await identityController.Refresh(new() { RefreshToken = refresh_token }, cancellationToken);
var refreshTokenResponse = await identityController.Refresh(new() { RefreshToken = refreshToken }, cancellationToken);
await StoreTokens(refreshTokenResponse);
return refreshTokenResponse.AccessToken!;
}
catch (Exception exp)
catch (UnauthorizedException)
{
if (exp is UnauthorizedException)
{
// refresh_token is either invalid or expired.
await ClearTokens();
}
exceptionHandler.Handle(exp, new()
{
{ "AdditionalData", "Refreshing access token failed." },
{ "RefreshTokenRequestedBy", requestedBy }
});
return null;
// refreshToken is either invalid or expired.
await ClearTokens();
throw;
}
}
finally
Expand All @@ -133,9 +142,9 @@ public override async Task<AuthenticationState> GetAuthenticationStateAsync()
{
try
{
var access_token = await prerenderStateService.GetValue(() => tokenProvider.GetAccessToken());
var accessToken = await prerenderStateService.GetValue(() => tokenProvider.GetAccessToken());

return new AuthenticationState(tokenProvider.ParseAccessToken(access_token, validateExpiry: false));
return new AuthenticationState(tokenProvider.ParseAccessToken(accessToken, validateExpiry: false));
}
catch (Exception exp)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ public interface IAuthTokenProvider

public ClaimsPrincipal Anonymous() => new(new ClaimsIdentity());

public ClaimsPrincipal ParseAccessToken(string? access_token, bool validateExpiry)
public ClaimsPrincipal ParseAccessToken(string? accessToken, bool validateExpiry)
{
if (string.IsNullOrEmpty(access_token) is true)
if (string.IsNullOrEmpty(accessToken) is true)
return Anonymous();

var claims = ReadClaims(access_token, validateExpiry);
var claims = ReadClaims(accessToken, validateExpiry);

if (claims is null)
return Anonymous();
Expand All @@ -25,9 +25,9 @@ public ClaimsPrincipal ParseAccessToken(string? access_token, bool validateExpir
return claimPrinciple;
}

private IEnumerable<Claim>? ReadClaims(string access_token, bool validateExpiry)
private IEnumerable<Claim>? ReadClaims(string accessToken, bool validateExpiry)
{
var parsedClaims = DeserializeAccessToken(access_token);
var parsedClaims = DeserializeAccessToken(accessToken);

if (validateExpiry && long.TryParse(parsedClaims["exp"].ToString(), out var expSeconds))
{
Expand Down Expand Up @@ -55,10 +55,10 @@ public ClaimsPrincipal ParseAccessToken(string? access_token, bool validateExpir
return claims;
}

private Dictionary<string, JsonElement> DeserializeAccessToken(string access_token)
private Dictionary<string, JsonElement> DeserializeAccessToken(string accessToken)
{
// Split the token to get the payload
string base64UrlPayload = access_token.Split('.')[1];
string base64UrlPayload = accessToken.Split('.')[1];

// Convert the payload from Base64Url format to Base64
string base64Payload = ConvertBase64UrlToBase64(base64UrlPayload);
Expand Down
Loading

0 comments on commit 87e0d6a

Please sign in to comment.