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 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 GetJwks() { var rsaSecurityKey = new RsaSecurityKey(jwtService.RsaKey.ExportParameters(false)) { KeyId = "TODO; keyid" }; var jsonWebKey = JsonWebKeyConverter.ConvertFromRSASecurityKey(rsaSecurityKey); return Ok(new JwksResponse { Keys = [jsonWebKey] }); } }