parent
af7b113035
commit
e6e6c73471
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||||
|
<data-source source="LOCAL" name="db" uuid="badf8e21-4e9b-45e6-a672-66a74dc1a74c">
|
||||||
|
<driver-ref>sqlite.xerial</driver-ref>
|
||||||
|
<synchronize>true</synchronize>
|
||||||
|
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
|
||||||
|
<jdbc-url>jdbc:sqlite:$PROJECT_DIR$/OAuthServer/db.sqlite3</jdbc-url>
|
||||||
|
<working-dir>$ProjectFileDir$</working-dir>
|
||||||
|
</data-source>
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="SqlDialectMappings">
|
||||||
|
<file url="PROJECT" dialect="SQLite" />
|
||||||
|
</component>
|
||||||
|
</project>
|
@ -0,0 +1,2 @@
|
|||||||
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
|
<s:String x:Key="/Default/CodeInspection/Highlighting/SweaWarningsMode/@EntryValue">ShowAndRun</s:String></wpf:ResourceDictionary>
|
@ -1,24 +1,78 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using OAuthServer.Services;
|
using OAuthServer.Services;
|
||||||
|
|
||||||
namespace OAuthServer.Controllers;
|
namespace OAuthServer.Controllers;
|
||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class OAuthController : ControllerBase
|
[Route("oauth")]
|
||||||
{
|
public class OAuthController : ControllerBase {
|
||||||
private readonly ILogger<OAuthController> _logger;
|
private readonly ILogger<OAuthController> _logger;
|
||||||
private readonly JwtService _jwt;
|
private readonly JwtService _jwt;
|
||||||
|
|
||||||
public OAuthController(ILogger<OAuthController> logger, JwtService jwt)
|
public OAuthController(ILogger<OAuthController> logger, JwtService jwt) {
|
||||||
{
|
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_jwt = jwt;
|
_jwt = jwt;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[Authorize]
|
||||||
[Route("get-token")]
|
[HttpGet("authorize")]
|
||||||
public ActionResult GenerateToken()
|
// ReSharper disable InconsistentNaming
|
||||||
{
|
public ActionResult Authorize(
|
||||||
return Ok(_jwt.GenerateToken());
|
[Required, Url] string redirect_uri,
|
||||||
|
string response_type,
|
||||||
|
string client_id,
|
||||||
|
string state
|
||||||
|
) {
|
||||||
|
if (string.IsNullOrEmpty(response_type) || string.IsNullOrEmpty(client_id) || string.IsNullOrEmpty(state)) {
|
||||||
|
return Redirect($"{redirect_uri}?error=invalid_request");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response_type != "code") {
|
||||||
|
return Redirect($"{redirect_uri}?error=unsupported_response_type&state={state}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (client_id != "lmao") {
|
||||||
|
return Redirect($"{redirect_uri}?error=access_denied&error_description=Invalid+client+id&state={state}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: generate code
|
||||||
|
string code = Guid.NewGuid().ToString();
|
||||||
|
|
||||||
|
return Redirect($"{redirect_uri}?code={code}&state={state}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public record GenerateTokenRequest(
|
||||||
|
string? grant_type,
|
||||||
|
string? code,
|
||||||
|
string? redirect_uri,
|
||||||
|
string? client_id,
|
||||||
|
string? client_secret
|
||||||
|
);
|
||||||
|
|
||||||
|
[HttpPost("token")]
|
||||||
|
[Consumes("application/x-www-form-urlencoded")]
|
||||||
|
public ActionResult GenerateToken([FromForm] GenerateTokenRequest request) {
|
||||||
|
if (string.IsNullOrEmpty(request.grant_type) || string.IsNullOrEmpty(request.code) ||
|
||||||
|
string.IsNullOrEmpty(request.redirect_uri) ||
|
||||||
|
string.IsNullOrEmpty(request.client_id)) {
|
||||||
|
return BadRequest(new {error = "invalid_request"});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.grant_type != "authorization_code") {
|
||||||
|
return BadRequest(new {error = "unsupported_grant_type"});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.client_id != "lmao") {
|
||||||
|
return BadRequest(new {error = "invalid_client"});
|
||||||
|
}
|
||||||
|
|
||||||
|
string token = _jwt.GenerateToken();
|
||||||
|
|
||||||
|
Response.Headers.Append("Cache-Control", "no-store");
|
||||||
|
Response.Headers.Append("Pragma", "no-cache");
|
||||||
|
|
||||||
|
return Ok(new {access_token = token, token_type = "bearer"});
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in new issue