Skip to content

Commit

Permalink
Merge pull request #27 from ITfoxtec/development
Browse files Browse the repository at this point in the history
Improve token response error handling.
  • Loading branch information
Revsgaard authored Nov 14, 2024
2 parents 58f9975 + 230f9a5 commit f0f92f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ The component automatically handle token / session update with use of the refres
<PackageTags>Blazor WebAssembly OpenID Connect (OIDC) Proof Key for Code Exchange (PKCE) id token access token refresh token</PackageTags>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Copyright>© 2024 ITfoxtec</Copyright>
<AssemblyVersion>1.6.6.0</AssemblyVersion>
<FileVersion>1.6.6.0</FileVersion>
<Version>1.6.6.0</Version>
<AssemblyVersion>1.6.7</AssemblyVersion>
<FileVersion>1.6.7</FileVersion>
<Version>1.6.7</Version>
</PropertyGroup>

<ItemGroup>
Expand All @@ -34,8 +34,8 @@ The component automatically handle token / session update with use of the refres

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Blazored.SessionStorage" Version="2.4.0" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="8.0.11" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.11" />
</ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net8.0'">
<DefineConstants>NET80;NET</DefineConstants>
Expand All @@ -53,8 +53,8 @@ The component automatically handle token / session update with use of the refres

<ItemGroup Condition=" '$(TargetFramework)' == 'net7.0'">
<PackageReference Include="Blazored.SessionStorage" Version="2.4.0" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="7.0.12" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.12" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="7.0.20" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.20" />
</ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net7.0'">
<DefineConstants>NET70;NET</DefineConstants>
Expand All @@ -72,8 +72,8 @@ The component automatically handle token / session update with use of the refres

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Blazored.SessionStorage" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="6.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="6.0.36" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="6.0.36" />
</ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net6.0'">
<DefineConstants>NET60;NET</DefineConstants>
Expand All @@ -91,8 +91,8 @@ The component automatically handle token / session update with use of the refres

<ItemGroup Condition=" '$(TargetFramework)' == 'net5.0'">
<PackageReference Include="Blazored.SessionStorage" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Components" Version="5.0.17" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.17" />
</ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net5.0'">
<DefineConstants>NET50;NET</DefineConstants>
Expand Down
9 changes: 3 additions & 6 deletions src/ITfoxtec.Identity.BlazorWA.Oidc/OpenidConnectPkce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public async Task LoginCallBackAsync(string responseUrl)
var request = new HttpRequestMessage(HttpMethod.Post, oidcDiscovery.TokenEndpoint);
request.Content = new FormUrlEncodedContent(requestDictionary);

var response = await GetHttpClient().SendAsync(request);
using var response = await GetHttpClient().SendAsync(request);
switch (response.StatusCode)
{
case HttpStatusCode.OK:
Expand All @@ -191,14 +191,11 @@ public async Task LoginCallBackAsync(string responseUrl)
var idTokenPrincipal = await oidcHelper.ValidateOidcWithUserInfoEndpoint(tokenResponse.IdToken, tokenResponse.AccessToken, openidClientPkceState.Nonce);
return (idTokenPrincipal, tokenResponse);

case HttpStatusCode.BadRequest:
default:
var resultBadRequest = await response.Content.ReadAsStringAsync();
var tokenResponseBadRequest = resultBadRequest.ToObject<TokenResponse>();
tokenResponseBadRequest.Validate(true);
throw new Exception($"Error login call back, Bad request. StatusCode={response.StatusCode}");

default:
throw new Exception($"Error login call back, Status Code not expected. StatusCode={response.StatusCode}");
throw new Exception($"Error login call back, unexpected status code. StatusCode={response.StatusCode}");
}
}

Expand Down

0 comments on commit f0f92f2

Please sign in to comment.