Compare commits

...

2 Commits

@ -15,7 +15,7 @@ public class OAuthController(
IDataProtectionProvider dataProtectionProvider
) : ControllerBase {
private readonly Dictionary<string, string> _clients = new() {
{"lmao", "yeet"},
{ "lmao", "yeet" },
};
@ -26,7 +26,8 @@ public class OAuthController(
[Required, Url] string redirect_uri,
string? response_type,
string? client_id,
string? state
string? state,
string? nonce
) {
if (string.IsNullOrEmpty(response_type) || string.IsNullOrEmpty(client_id) || string.IsNullOrEmpty(state)) {
return Redirect($"{redirect_uri}?error=invalid_request");
@ -45,7 +46,8 @@ public class OAuthController(
CodeObject codeObject = new CodeObject(
ClientId: client_id,
RedirectUri: redirect_uri,
Expiry: DateTime.UtcNow.AddMinutes(5)
Expiry: DateTime.UtcNow.AddMinutes(5),
Nonce: nonce
);
string code = protector.Protect(JsonSerializer.Serialize(codeObject));
@ -69,21 +71,21 @@ public class OAuthController(
string.IsNullOrEmpty(request.redirect_uri) ||
string.IsNullOrEmpty(request.client_id) ||
string.IsNullOrEmpty(request.client_secret)) {
return BadRequest(new {error = "invalid_request"});
return BadRequest(new { error = "invalid_request" });
}
if (request.grant_type != "authorization_code") {
return BadRequest(new {error = "unsupported_grant_type"});
return BadRequest(new { error = "unsupported_grant_type" });
}
if (!_clients.TryGetValue(request.client_id, out string? clientSecret)) {
logger.LogInformation("Unknown client id");
return BadRequest(new {error = "unauthorized_client"});
return BadRequest(new { error = "unauthorized_client" });
}
if (request.client_secret != clientSecret) {
logger.LogInformation("Invalid client secret");
return BadRequest(new {error = "unauthorized_client"});
return BadRequest(new { error = "unauthorized_client" });
}
IDataProtector protector = dataProtectionProvider.CreateProtector("oauth");
@ -91,29 +93,42 @@ public class OAuthController(
try {
codeObject = JsonSerializer.Deserialize<CodeObject>(protector.Unprotect(request.code));
} catch (Exception) {
return BadRequest(new {error = "invalid_request"});
return BadRequest(new { error = "invalid_request" });
}
if (codeObject == null) {
return BadRequest(new {error = "invalid_request"});
return BadRequest(new { error = "invalid_request" });
}
if (codeObject.ClientId != request.client_id || codeObject.RedirectUri != request.redirect_uri) {
return BadRequest(new {error = "invalid_request"});
return BadRequest(new { error = "invalid_request" });
}
if (DateTime.UtcNow > codeObject.Expiry) {
logger.LogInformation("Expired token");
return BadRequest(new {error = "invalid_grant"});
return BadRequest(new { error = "invalid_grant" });
}
string token = jwt.GenerateToken();
string token = jwt.GenerateToken(codeObject.ClientId, codeObject.Nonce);
Response.Headers.Append("Cache-Control", "no-store");
Response.Headers.Append("Pragma", "no-cache");
return Ok(new {access_token = token, token_type = "bearer"});
return Ok(new { access_token = token, token_type = "bearer", id_token = token });
}
private record CodeObject(string ClientId, string RedirectUri, DateTime Expiry);
[Authorize]
[HttpGet("user")]
public ActionResult UserInfo() {
return Ok(new {
sub = "248289761001",
name = "Jane Doe",
// given_name = "Jane",
// family_name = "Doe",
// preferred_username = "j.doe",
email = "janedoe@example.com",
});
}
private record CodeObject(string ClientId, string RedirectUri, DateTime Expiry, string? Nonce);
}

@ -0,0 +1,46 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.IdentityModel.Tokens;
using OAuthServer.Responses;
using OAuthServer.Services;
namespace OAuthServer.Controllers;
[ApiController]
public class OpenIdController(
JwtService jwtService
) : ControllerBase {
[HttpGet("/.well-known/openid-configuration")]
public ActionResult<OpenIdConfiguration> GetOpenIdConfiguration() {
return Ok(new OpenIdConfiguration {
Issuer = "http://localhost:1234",
AuthorizationEndpoint = "http://localhost:1234/oauth/authorize",
TokenEndpoint = "http://localhost:1234/oauth/token",
UserInfoEndpoint = "http://localhost:1234/oauth/user",
JwksUri = "http://localhost:1234/.well-known/jwks.json",
ScopesSupported = ["openid"],
ResponseTypesSupported = ["code"],
GrantTypesSupported = ["authorization_code"],
SubjectTypesSupported = ["public"],
IdTokenSigningAlgValuesSupported = ["RS256"],
ClaimsSupported = [
"aud",
"exp",
"iat",
"iss",
"sub"
]
});
}
[HttpGet("/.well-known/jwks.json")]
public ActionResult<JwksResponse> GetJwks() {
var rsaSecurityKey = new RsaSecurityKey(jwtService.RsaKey.ExportParameters(false)) {
KeyId = "TODO; keyid"
};
var jsonWebKey = JsonWebKeyConverter.ConvertFromRSASecurityKey(rsaSecurityKey);
return Ok(new JwksResponse {
Keys = [jsonWebKey]
});
}
}

@ -1,3 +1,4 @@
using System.Text.Json.Serialization;
using Microsoft.AspNetCore.DataProtection;
using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption;
using Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel;
@ -14,7 +15,9 @@ var builder = WebApplication.CreateBuilder(args);
builder.Logging.AddConsole();
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddControllers().AddJsonOptions(options => {
options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
});
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options => {
// Create a authentication schema for JWT tokens

@ -0,0 +1,29 @@
using System.Text.Json.Serialization;
using Microsoft.IdentityModel.Tokens;
namespace OAuthServer.Responses;
public record JwksResponse {
[JsonPropertyName("keys")]
public required IEnumerable<JsonWebKey> Keys { get; init; }
}
/*
{
"keys": [
{
"kid": "2B9DDE7B1F697B8F373C7B67B8F9946377ABD942",
"use": "sig",
"kty": "RSA",
"alg": "RS256",
"e": "AQAB",
"n": "no8jy5nrjOAzIlMFLyAy7iWotB0V2We673MAt61jdMfoSG10I34BO_ybW9_ZRLyQUIf9SBYbhA6tDRPoUATUbGCEUoTtUvqQJdfWUrLC-GdwLqCvqAYqGOMwLGyDdKJCQBh5sVMuCX6fG_6bm3jN8O7w5SiZHPF8dZuD_GUEdkRG_tmLjfyo82tfQmIkbD0kMQh9gh2H_YmmaZVLNjsvus0TEls35vZIvAXLIUAyscw6QPi05v3gvtkTGNNVUjC-2-zfPtcDl_zWb3Z73Q3S05FKCy0NubQBx5p2MarpdtigFzOs_hQrF64Oe1Xd_eJudODQCrOCso64mEHoOf5yuQ",
"x5t": "K53eex9pe483PHtnuPmUY3er2UI",
"x5c": [
"MIIC9TCCAd2gAwIBAgIJAPchcyLCUuqrMA0GCSqGSIb3DQEBCwUAMDAxLjAsBgNVBAMTJU9wZW5JZGRpY3QgU2VydmVyIFNpZ25pbmcgQ2VydGlmaWNhdGUwHhcNMjUwODA1MTg1MTExWhcNMjcwODA1MTg1MTExWjAwMS4wLAYDVQQDEyVPcGVuSWRkaWN0IFNlcnZlciBTaWduaW5nIENlcnRpZmljYXRlMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAno8jy5nrjOAzIlMFLyAy7iWotB0V2We673MAt61jdMfoSG10I34BO/ybW9/ZRLyQUIf9SBYbhA6tDRPoUATUbGCEUoTtUvqQJdfWUrLC+GdwLqCvqAYqGOMwLGyDdKJCQBh5sVMuCX6fG/6bm3jN8O7w5SiZHPF8dZuD/GUEdkRG/tmLjfyo82tfQmIkbD0kMQh9gh2H/YmmaZVLNjsvus0TEls35vZIvAXLIUAyscw6QPi05v3gvtkTGNNVUjC+2+zfPtcDl/zWb3Z73Q3S05FKCy0NubQBx5p2MarpdtigFzOs/hQrF64Oe1Xd/eJudODQCrOCso64mEHoOf5yuQIDAQABoxIwEDAOBgNVHQ8BAf8EBAMCB4AwDQYJKoZIhvcNAQELBQADggEBAG6zIRJusZTawdXAiuZ7+hymJ2uzBxDawmG+S5+S4yf7l0SsPkW/zhzlShbLifhupHzAuu3bRJ9OKHHQrRsmteN+qMS4zbgNB8jpAroYL0MrXCIhp8BWgjQOKeakE59jIEFyuv342ATL7qWUuo+oUKJHgiWcHPNj102HFRth0rodSLjnjTSk2Kha0Uj/p7cHXRcp8yfBV8cs9ym6cVUJj24jveQBC31tXEE3Rx+dgEKOzUdkrogHRhQJdEfqovuuPcSgVxWpHlFCSOeNvnd53vL6jy5NQtO0Ld4fxa7oh3MTlfHjZoPU4m9pGC35xyk8LiwEuMwWKWaWgyBPnLhcnwY="
]
}
]
}
*/

@ -0,0 +1,276 @@
using System.Text.Json.Serialization;
namespace OAuthServer.Responses;
// Source: https://openid.net/specs/openid-connect-discovery-1_0.html#OpenID.Core
public record OpenIdConfiguration {
/// <summary>
/// REQUIRED. URL using the https scheme with no query or fragment components that the OP asserts as its Issuer Identifier. If Issuer discovery is supported (see Section 2), this value MUST be identical to the issuer value returned by WebFinger. This also MUST be identical to the iss Claim value in ID Tokens issued from this Issuer.
/// </summary>
[JsonPropertyName("issuer")]
public required string Issuer { get; init; }
/// <summary>
/// REQUIRED. URL of the OP's OAuth 2.0 Authorization Endpoint [OpenID.Core]. This URL MUST use the https scheme and MAY contain port, path, and query parameter components.
/// </summary>
[JsonPropertyName("authorization_endpoint")]
public required string AuthorizationEndpoint { get; init; }
/// <summary>
/// URL of the OP's OAuth 2.0 Token Endpoint [OpenID.Core]. This is REQUIRED unless only the Implicit Flow is used. This URL MUST use the https scheme and MAY contain port, path, and query parameter components.
/// </summary>
[JsonPropertyName("token_endpoint")]
public required string TokenEndpoint { get; init; }
/// <summary>
/// RECOMMENDED. URL of the OP's UserInfo Endpoint [OpenID.Core]. This URL MUST use the https scheme and MAY contain port, path, and query parameter components.
/// </summary>
[JsonPropertyName("userinfo_endpoint")]
public string? UserInfoEndpoint { get; init; }
/// <summary>
/// REQUIRED. URL of the OP's JWK Set [JWK] document, which MUST use the https scheme. This contains the signing key(s) the RP uses to validate signatures from the OP. The JWK Set MAY also contain the Server's encryption key(s), which are used by RPs to encrypt requests to the Server. When both signing and encryption keys are made available, a use (public key use) parameter value is REQUIRED for all keys in the referenced JWK Set to indicate each key's intended usage. Although some algorithms allow the same key to be used for both signatures and encryption, doing so is NOT RECOMMENDED, as it is less secure. The JWK x5c parameter MAY be used to provide X.509 representations of keys provided. When used, the bare key values MUST still be present and MUST match those in the certificate. The JWK Set MUST NOT contain private or symmetric key values.
/// </summary>
[JsonPropertyName("jwks_uri")]
public required string JwksUri { get; init; }
/// <summary>
/// RECOMMENDED. URL of the OP's Dynamic Client Registration Endpoint [OpenID.Registration], which MUST use the https scheme.
/// </summary>
[JsonPropertyName("registration_endpoint")]
public string? RegistrationEndpoint { get; init; }
/// <summary>
/// RECOMMENDED. JSON array containing a list of the OAuth 2.0 [RFC6749] scope values that this server supports. The server MUST support the openid scope value. Servers MAY choose not to advertise some supported scope values even when this parameter is used, although those defined in [OpenID.Core] SHOULD be listed, if supported.
/// </summary>
[JsonPropertyName("scopes_supported")]
public string[]? ScopesSupported { get; init; }
/// <summary>
/// REQUIRED. JSON array containing a list of the OAuth 2.0 response_type values that this OP supports. Dynamic OpenID Providers MUST support the code, id_token, and the id_token token Response Type values.
/// </summary>
[JsonPropertyName("response_types_supported")]
public required string[] ResponseTypesSupported { get; init; }
/// <summary>
/// OPTIONAL. JSON array containing a list of the OAuth 2.0 response_mode values that this OP supports, as specified in OAuth 2.0 Multiple Response Type Encoding Practices [OAuth.Responses]. If omitted, the default for Dynamic OpenID Providers is ["query", "fragment"].
/// </summary>
[JsonPropertyName("response_modes_supported")]
public string[]? ResponseModesSupported { get; init; }
/// <summary>
/// OPTIONAL. JSON array containing a list of the OAuth 2.0 Grant Type values that this OP supports. Dynamic OpenID Providers MUST support the authorization_code and implicit Grant Type values and MAY support other Grant Types. If omitted, the default value is ["authorization_code", "implicit"].
/// </summary>
[JsonPropertyName("grant_types_supported")]
public string[]? GrantTypesSupported { get; init; }
/// <summary>
/// OPTIONAL. JSON array containing a list of the Authentication Context Class References that this OP supports.
/// </summary>
[JsonPropertyName("acr_values_supported")]
public string[]? AcrValuesSupported { get; init; }
/// <summary>
/// REQUIRED. JSON array containing a list of the Subject Identifier types that this OP supports. Valid types include pairwise and public.
/// </summary>
[JsonPropertyName("subject_types_supported")]
public required string[] SubjectTypesSupported { get; init; }
/// <summary>
/// REQUIRED. JSON array containing a list of the JWS signing algorithms (alg values) supported by the OP for the ID Token to encode the Claims in a JWT [JWT]. The algorithm RS256 MUST be included. The value none MAY be supported but MUST NOT be used unless the Response Type used returns no ID Token from the Authorization Endpoint (such as when using the Authorization Code Flow).
/// </summary>
[JsonPropertyName("id_token_signing_alg_values_supported")]
public required string[] IdTokenSigningAlgValuesSupported { get; init; }
/// <summary>
/// OPTIONAL. JSON array containing a list of the JWE encryption algorithms (alg values) supported by the OP for the ID Token to encode the Claims in a JWT [JWT].
/// </summary>
[JsonPropertyName("id_token_encryption_alg_values_supported")]
public string[]? IdTokenEncryptionAlgValuesSupported { get; init; }
/// <summary>
/// OPTIONAL. JSON array containing a list of the JWE encryption algorithms (enc values) supported by the OP for the ID Token to encode the Claims in a JWT [JWT].
/// </summary>
[JsonPropertyName("id_token_encryption_enc_values_supported")]
public string[]? IdTokenEncryptionEncValuesSupported { get; init; }
/// <summary>
/// OPTIONAL. JSON array containing a list of the JWS [JWS] signing algorithms (alg values) [JWA] supported by the UserInfo Endpoint to encode the Claims in a JWT [JWT]. The value none MAY be included.
/// </summary>
[JsonPropertyName("userinfo_signing_alg_values_supported")]
public string[]? UserinfoSigningAlgValuesSupported { get; init; }
/// <summary>
/// OPTIONAL. JSON array containing a list of the JWE [JWE] encryption algorithms (alg values) [JWA] supported by the UserInfo Endpoint to encode the Claims in a JWT [JWT].
/// </summary>
[JsonPropertyName("userinfo_encryption_alg_values_supported")]
public string[]? UserinfoEncryptionAlgValuesSupported { get; init; }
/// <summary>
/// OPTIONAL. JSON array containing a list of the JWE encryption algorithms (enc values) [JWA] supported by the UserInfo Endpoint to encode the Claims in a JWT [JWT].
/// </summary>
[JsonPropertyName("userinfo_encryption_enc_values_supported")]
public string[]? UserinfoEncryptionEncValuesSupported { get; init; }
/// <summary>
/// OPTIONAL. JSON array containing a list of the JWS signing algorithms (alg values) supported by the OP for Request Objects, which are described in Section 6.1 of OpenID Connect Core 1.0 [OpenID.Core]. These algorithms are used both when the Request Object is passed by value (using the request parameter) and when it is passed by reference (using the request_uri parameter). Servers
/// </summary>
[JsonPropertyName("request_object_signing_alg_values_supported")]
public string[]? RequestObjectSigningAlgValuesSupported { get; init; }
/// <summary>
/// OPTIONAL. JSON array containing a list of the JWE encryption algorithms (alg values) supported by the OP for Request Objects. These algorithms are used both when the Request Object is passed by value and when it is passed by reference.
/// </summary>
[JsonPropertyName("request_object_encryption_alg_values_supported")]
public string[]? RequestObjectEncryptionAlgValuesSupported { get; init; }
/// <summary>
/// OPTIONAL. JSON array containing a list of the JWE encryption algorithms (enc values) supported by the OP for Request Objects. These algorithms are used both when the Request Object is passed by value and when it is passed by reference.
/// </summary>
[JsonPropertyName("request_object_encryption_enc_values_supported")]
public string[]? RequestObjectEncryptionEncValuesSupported { get; init; }
/// <summary>
/// OPTIONAL. JSON array containing a list of Client Authentication methods supported by this Token Endpoint. The options are client_secret_post, client_secret_basic, client_secret_jwt, and private_key_jwt, as described in Section 9 of OpenID Connect Core 1.0 [OpenID.Core]. Other authentication methods MAY be defined by extensions. If omitted, the default is client_secret_basic -- the HTTP Basic Authentication Scheme specified in Section 2.3.1 of OAuth 2.0 [RFC6749].
/// </summary>
[JsonPropertyName("token_endpoint_auth_methods_supported")]
public string[]? TokenEndpointAuthMethodsSupported { get; init; }
/// <summary>
/// OPTIONAL. JSON array containing a list of the JWS signing algorithms (alg values) supported by the Token Endpoint for the signature on the JWT [JWT] used to authenticate the Client at the Token Endpoint for the private_key_jwt and client_secret_jwt authentication methods. Servers SHOULD support RS256. The value none MUST NOT be used.
/// </summary>
[JsonPropertyName("token_endpoint_auth_signing_alg_values_supported")]
public string[]? TokenEndpointAuthSigningAlgValuesSupported { get; init; }
/// <summary>
/// OPTIONAL. JSON array containing a list of the display parameter values that the OpenID Provider supports. These values are described in Section 3.1.2.1 of OpenID Connect Core 1.0 [OpenID.Core].
/// </summary>
[JsonPropertyName("display_values_supported")]
public string[]? DisplayValuesSupported { get; init; }
/// <summary>
/// OPTIONAL. JSON array containing a list of the Claim Types that the OpenID Provider supports. These Claim Types are described in Section 5.6 of OpenID Connect Core 1.0 [OpenID.Core]. Values defined by this specification are normal, aggregated, and distributed. If omitted, the implementation supports only normal Claims.
/// </summary>
[JsonPropertyName("claim_types_supported")]
public string[]? ClaimTypesSupported { get; init; }
/// <summary>
/// RECOMMENDED. JSON array containing a list of the Claim Names of the Claims that the OpenID Provider MAY be able to supply values for. Note that for privacy or other reasons, this might not be an exhaustive list.
/// </summary>
[JsonPropertyName("claims_supported")]
public string[]? ClaimsSupported { get; init; }
/// <summary>
/// OPTIONAL. URL of a page containing human-readable information that developers might want or need to know when using the OpenID Provider. In particular, if the OpenID Provider does not support Dynamic Client Registration, then information on how to register Clients needs to be provided in this documentation.
/// </summary>
[JsonPropertyName("service_documentation")]
public string? ServiceDocumentation { get; init; }
/// <summary>
/// OPTIONAL. Languages and scripts supported for values in Claims being returned, represented as a JSON array of BCP47 [RFC5646] language tag values. Not all languages and scripts are necessarily supported for all Claim values.
/// </summary>
[JsonPropertyName("claims_locales_supported")]
public string[]? ClaimsLocalesSupported { get; init; }
/// <summary>
/// OPTIONAL. Languages and scripts supported for the user interface, represented as a JSON array of BCP47 [RFC5646] language tag values.
/// </summary>
[JsonPropertyName("ui_locales_supported")]
public string[]? UiLocalesSupported { get; init; }
/// <summary>
/// OPTIONAL. Boolean value specifying whether the OP supports use of the claims parameter, with true indicating support. If omitted, the default value is false.
/// </summary>
[JsonPropertyName("claims_parameter_supported")]
public bool? ClaimsParameterSupported { get; init; }
/// <summary>
/// OPTIONAL. Boolean value specifying whether the OP supports use of the request parameter, with true indicating support. If omitted, the default value is false.
/// </summary>
[JsonPropertyName("request_parameter_supported")]
public bool? RequestParameterSupported { get; init; }
/// <summary>
/// OPTIONAL. Boolean value specifying whether the OP supports use of the request_uri parameter, with true indicating support. If omitted, the default value is true.
/// </summary>
[JsonPropertyName("request_uri_parameter_supported")]
public bool? RequestUriParameterSupported { get; init; }
/// <summary>
/// OPTIONAL. Boolean value specifying whether the OP requires any request_uri values used to be pre-registered using the request_uris registration parameter. Pre-registration is REQUIRED when the value is true. If omitted, the default value is false.
/// </summary>
[JsonPropertyName("require_request_uri_registration")]
public bool? RequireRequestUriRegistration { get; init; }
/// <summary>
/// OPTIONAL. URL that the OpenID Provider provides to the person registering the Client to read about the OP's requirements on how the Relying Party can use the data provided by the OP. The registration process SHOULD display this URL to the person registering the Client if it is given.
/// </summary>
[JsonPropertyName("op_policy_uri")]
public string? OpPolicyUri { get; init; }
/// <summary>
/// OPTIONAL. URL that the OpenID Provider provides to the person registering the Client to read about the OpenID Provider's terms of service. The registration process SHOULD display this URL to the person registering the Client if it is given.
/// </summary>
[JsonPropertyName("op_tos_uri")]
public string? OpTosUri { get; init; }
}
/*
{
"issuer": "http://localhost:5119/",
"authorization_endpoint": "http://localhost:5119/authorize",
"token_endpoint": "http://localhost:5119/token",
"userinfo_endpoint": "http://localhost:5119/user",
"jwks_uri": "http://localhost:5119/.well-known/jwks",
"grant_types_supported": [
"authorization_code"
],
"response_types_supported": [
"code"
],
"response_modes_supported": [
"query",
"form_post",
"fragment"
],
"scopes_supported": [
"openid"
],
"claims_supported": [
"aud",
"exp",
"iat",
"iss",
"sub"
],
"id_token_signing_alg_values_supported": [
"RS256"
],
"code_challenge_methods_supported": [
"plain",
"S256"
],
"subject_types_supported": [
"public"
],
"prompt_values_supported": [
"consent",
"login",
"none",
"select_account"
],
"token_endpoint_auth_methods_supported": [
"client_secret_post",
"private_key_jwt",
"client_secret_basic"
],
"require_pushed_authorization_requests": false,
"claims_parameter_supported": false,
"request_parameter_supported": false,
"request_uri_parameter_supported": false,
"tls_client_certificate_bound_access_tokens": false,
"authorization_response_iss_parameter_supported": true
}
*/

@ -6,10 +6,10 @@ using Microsoft.IdentityModel.Tokens;
namespace OAuthServer.Services;
public class JwtService {
private readonly RSA _rsaKey;
public readonly RSA RsaKey;
public JwtService() {
_rsaKey = GetSigningKey();
RsaKey = GetSigningKey();
}
public static RSA GetSigningKey() {
@ -31,15 +31,22 @@ public class JwtService {
return rsaKey;
}
public string GenerateToken() {
public string GenerateToken(string audience, string? nonce) {
var handler = new JsonWebTokenHandler();
var key = new RsaSecurityKey(_rsaKey);
var key = new RsaSecurityKey(RsaKey);
var claims = new List<Claim> {
new(JwtRegisteredClaimNames.Iss, "http://localhost:1234"),
new(JwtRegisteredClaimNames.Sub, "user1"),
new(JwtRegisteredClaimNames.Aud, audience),
new("role", "External"),
new("scope", "scope:1"),
};
if (nonce != null) {
claims.Add(new Claim(JwtRegisteredClaimNames.Nonce, nonce));
}
var token = handler.CreateToken(new SecurityTokenDescriptor {
Subject = new ClaimsIdentity(new[] {
new Claim(JwtRegisteredClaimNames.Sub, "user1"),
new Claim("role", "External"),
new Claim("scope", "scope:1")
}),
Subject = new ClaimsIdentity(claims),
Expires = DateTime.UtcNow.AddDays(10),
SigningCredentials = new SigningCredentials(key, SecurityAlgorithms.RsaSha256)
});

Loading…
Cancel
Save