Add public Key get
Docker Build and Release Upload / build (push) Successful in 1m26s

This commit is contained in:
2025-07-26 11:52:08 -07:00
parent 72a500405a
commit 32980f6075
+25 -2
View File
@@ -7,6 +7,8 @@ using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using Auth.Services;
using Auth.DTO;
using System.Security.Cryptography;
using System.Text;
namespace Auth.Controllers {
[ApiController]
@@ -15,7 +17,27 @@ namespace Auth.Controllers {
public MAuthController(DatabaseService db) : base(db) { }
// Login and return a ticket to retreive your JWT
// Sends the public key to clients so they can verify sessions.
[HttpGet("publickey")]
public IActionResult PublicKey() {
try {
RSA rsa = AuthJWT.RsaPublicKey.Rsa;
rsa.ImportParameters(AuthJWT.RsaPublicKey.Parameters);
byte[] publicKey = rsa.ExportSubjectPublicKeyInfo();
string base64 = Convert.ToBase64String(publicKey);
StringBuilder sb = new StringBuilder();
sb.AppendLine("-----BEGIN PUBLIC KEY-----");
for (int i = 0; i < base64.Length; i += 64) {
sb.AppendLine(base64.Substring(i, Math.Min(64, base64.Length - i)));
}
sb.AppendLine("-----END PUBLIC KEY-----");
return Ok(sb.ToString());
} catch (SecurityTokenException ex) {
return BadRequest("Token invalid: " + ex.Message);
}
}
// Login and return a ticket to retreive your JWT - Verified working
[HttpPost("login")]
public async Task<ActionResult> Authenticate([FromBody] LoginRequest request) {
try {
@@ -54,6 +76,7 @@ namespace Auth.Controllers {
}
}
// Use your ticket to get the JWT - Verified working
[HttpPost("token")]
public ActionResult Token([FromBody] JWTRequest request) {
try {
@@ -75,7 +98,7 @@ namespace Auth.Controllers {
}
}
// Renews an old JWT before it expires
// Renews an old JWT before it expires - Not Tested
[HttpPost("renew")]
public IActionResult Session([FromBody] JWTRenewRequest request) {
try {