Skip to content

Commit fcdd76d

Browse files
committed
jwt auth endpoint hit :WIP
1 parent d34bd1e commit fcdd76d

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

src/Api/Xero.Demo.Infrastructure/Extensions/AddAuthorizationExtension.cs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,23 @@ public static IServiceCollection AddRolesAndPolicyAuthorization(this IServiceCol
5555

5656
public static IServiceCollection AddJwtAuthentication(this IServiceCollection services, IConfiguration configuration)
5757
{
58-
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
58+
services.AddAuthentication(x =>
5959
{
60-
options.RequireHttpsMetadata = false;
61-
options.Audience = "http://localhost:5001/";
62-
options.Authority = "http://localhost:5000/";
63-
options.TokenValidationParameters = new TokenValidationParameters
64-
{
65-
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["AppSettings:Secret"])),
66-
ClockSkew = TimeSpan.Zero
67-
};
68-
});
60+
x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
61+
x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
62+
})
63+
.AddJwtBearer(x =>
64+
{
65+
x.RequireHttpsMetadata = false;
66+
x.SaveToken = true;
67+
x.TokenValidationParameters = new TokenValidationParameters
68+
{
69+
ValidateIssuerSigningKey = true,
70+
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes("hdftasdvjrlvfvfjyvwevfcmdfkjsdnhvzfmbnsdfvm")),
71+
ValidateIssuer = false,
72+
ValidateAudience = false
73+
};
74+
});
6975
return services;
7076
}
7177
}

src/Api/Xero.Demo.Infrastructure/Extensions/AddMiddleWareExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static void AddServices(this IServiceCollection services, IConfiguration
3131
//.LogTo(Console.WriteLine)
3232
;
3333
});
34-
34+
services.AddCors();
3535
services.AddLocalizationServices();
3636

3737
services.AddApiVersioning(options =>

src/Api/Xero.Demo.Infrastructure/Extensions/UseMiddleWareExtension.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ public static void UseMiddleware(this IApplicationBuilder app, IApiVersionDescri
4040
app.UseRequestResponseLogging();
4141
app.UseMiddleware<JwtMiddleware>();
4242
app.UseAuthentication();
43-
app.UseAuthorization();
43+
app.UseCors(x => x
44+
.AllowAnyOrigin()
45+
.AllowAnyMethod()
46+
.AllowAnyHeader());
47+
4448
app.UseEndpoints(endpoints =>
4549
{
4650
endpoints.MapControllers();

src/Api/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"PRODUCTOPTION": "true"
1515
},
1616
"AppSettings": {
17-
"Secret": "abcdefghijklmnopqrstuvwxyz1234567890"
17+
"Secret": "hdftasdvjrlvfvfjyvwevfcmdfkjsdnhvzfmbnsdfvm"
1818
},
1919
"AppOptions": {
2020
"Culture": "fa-FR", // fa-FR for Persian

0 commit comments

Comments
 (0)