-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigureJwtBearerOptions.cs
37 lines (31 loc) · 1.3 KB
/
ConfigureJwtBearerOptions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) Demo AG. All Rights Reserved.
using DevEpos.CF.Demo.Env;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.Options;
using Microsoft.IdentityModel.Tokens;
namespace DevEpos.CF.Demo.Authentication;
/// <summary>
/// JWT bearer options for authentication configuration
/// </summary>
public class ConfigureJwtBearerOptions : IConfigureNamedOptions<JwtBearerOptions> {
private readonly IKeyManager _keyManager;
private readonly IServiceEnv _env;
public ConfigureJwtBearerOptions(IKeyManager keyManager, IServiceEnv env) {
_keyManager = keyManager;
_env = env;
}
public void Configure(JwtBearerOptions o) {
o.TokenValidationParameters = new TokenValidationParameters {
ValidIssuer = $"{_env.XsuaaCredentials.First().Url}/oauth/token",
ValidAudience = _env.XsuaaCredentials.First().XsAppName,
ValidateLifetime = true,
IssuerSigningKeyResolver = (string t, SecurityToken securityToken, string kid, TokenValidationParameters tokenParams) =>
[_keyManager.GetSecurityKey(kid, securityToken)],
ValidateIssuer = true,
ValidateIssuerSigningKey = true
};
}
public void Configure(string? name, JwtBearerOptions o) {
Configure(o);
}
}