Skip to content

Commit

Permalink
fix: jwt validation
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobritodev committed Apr 5, 2022
1 parent 502e365 commit 93d3afd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
3 changes: 0 additions & 3 deletions samples/NetDevPack.Security.Jwt.AspNet.SymetricKey/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Security.Claims;
using System.Text;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.JsonWebTokens;
using Microsoft.IdentityModel.Logging;
using Microsoft.IdentityModel.Tokens;
Expand All @@ -11,7 +9,6 @@
using NetDevPack.Security.Jwt.AspNetCore;
using NetDevPack.Security.Jwt.Core;
using NetDevPack.Security.Jwt.Core.Interfaces;
using NetDevPack.Security.Jwt.Core.Jwa;


var builder = WebApplication.CreateBuilder(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static IApplicationBuilder UseJwksDiscovery(this IApplicationBuilder app,
public static IJwksBuilder UseJwtValidation(this IJwksBuilder builder)
{

builder.Services.AddSingleton<IPostConfigureOptions<JwtBearerOptions>, JwtPostConfigureOptions>();
builder.Services.AddSingleton<IPostConfigureOptions<JwtBearerOptions>>(s => new JwtPostConfigureOptions(s));

return builder;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using NetDevPack.Security.Jwt.Core.Interfaces;

Expand All @@ -9,9 +10,10 @@ public class JwtPostConfigureOptions : IPostConfigureOptions<JwtBearerOptions>
private readonly IJwtService _jwtService;
// private readonly MyCustomSecurityTokenValidator _tokenValidator; //example dependancy

public JwtPostConfigureOptions(IJwtService jwtService)
public JwtPostConfigureOptions(IServiceProvider service)
{
_jwtService = jwtService;
using var scope = service.CreateScope();
_jwtService = scope.ServiceProvider.GetRequiredService<IJwtService>();
}

public void PostConfigure(string name, JwtBearerOptions options)
Expand Down

0 comments on commit 93d3afd

Please sign in to comment.