WIP OAuth token grant
This commit is contained in:
parent
5556ca85f4
commit
a9d25a1492
6 changed files with 129 additions and 8 deletions
|
@ -21,10 +21,6 @@
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="7.1.0"/>
|
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="7.1.0"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Controllers\"/>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Astral.Services\Astral.Services.csproj"/>
|
<ProjectReference Include="..\Astral.Services\Astral.Services.csproj"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
16
Astral.ApiServer/Constants/OAuthGrantTypes.cs
Normal file
16
Astral.ApiServer/Constants/OAuthGrantTypes.cs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
// <copyright file="OAuthGrantTypes.cs" company="alveus.dev">
|
||||||
|
// Copyright (c) alveus.dev. All rights reserved. Licensed under the MIT License.
|
||||||
|
// </copyright>
|
||||||
|
|
||||||
|
namespace Astral.ApiServer.Constants;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Available grant types for auth token requests.
|
||||||
|
/// </summary>
|
||||||
|
public static class OAuthGrantTypes
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Password grant type.
|
||||||
|
/// </summary>
|
||||||
|
public const string Password = "password";
|
||||||
|
}
|
29
Astral.ApiServer/Controllers/OAuthController.cs
Normal file
29
Astral.ApiServer/Controllers/OAuthController.cs
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
// <copyright file="OAuthController.cs" company="alveus.dev">
|
||||||
|
// Copyright (c) alveus.dev. All rights reserved. Licensed under the MIT License.
|
||||||
|
// </copyright>
|
||||||
|
|
||||||
|
using Astral.ApiServer.Models;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Astral.ApiServer.Controllers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// OAuth authentication controller.
|
||||||
|
/// </summary>
|
||||||
|
[Produces("application/json")]
|
||||||
|
[Consumes("application/x-www-form-urlencoded")]
|
||||||
|
[Route("oauth")]
|
||||||
|
public class OAuthController : ControllerBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Grant token request.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tokenGrantRequest">Instance of <see cref="TokenGrantRequestModel"/>.</param>
|
||||||
|
[HttpPost("token")]
|
||||||
|
[AllowAnonymous]
|
||||||
|
public Task<IActionResult> GrantToken([FromForm] TokenGrantRequestModel tokenGrantRequest)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
43
Astral.ApiServer/Models/TokenGrantRequestModel.cs
Normal file
43
Astral.ApiServer/Models/TokenGrantRequestModel.cs
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
// <copyright file="TokenGrantRequestModel.cs" company="alveus.dev">
|
||||||
|
// Copyright (c) alveus.dev. All rights reserved. Licensed under the MIT License.
|
||||||
|
// </copyright>
|
||||||
|
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Astral.ApiServer.Models;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Oauth token grant request.
|
||||||
|
/// </summary>
|
||||||
|
public class TokenGrantRequestModel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The grant type of the request.
|
||||||
|
/// </summary>
|
||||||
|
[FromForm(Name = "grant_type")]
|
||||||
|
public string GrantType { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Refresh token.
|
||||||
|
/// </summary>
|
||||||
|
[FromForm(Name = "refresh_token")]
|
||||||
|
public string RefreshToken { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Username.
|
||||||
|
/// </summary>
|
||||||
|
[FromForm(Name = "username")]
|
||||||
|
public string Username { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Password.
|
||||||
|
/// </summary>
|
||||||
|
[FromForm(Name = "password")]
|
||||||
|
public string Password { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Scope.
|
||||||
|
/// </summary>
|
||||||
|
[FromForm(Name = "scope")]
|
||||||
|
public string Scope { get; set; }
|
||||||
|
}
|
37
Astral.ApiServer/Models/TokenGrantResponseModel.cs
Normal file
37
Astral.ApiServer/Models/TokenGrantResponseModel.cs
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
// <copyright file="TokenGrantResponseModel.cs" company="alveus.dev">
|
||||||
|
// Copyright (c) alveus.dev. All rights reserved. Licensed under the MIT License.
|
||||||
|
// </copyright>
|
||||||
|
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace Astral.ApiServer.Models;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// OAuth Grant Request Response.
|
||||||
|
/// </summary>
|
||||||
|
public class TokenGrantResponseModel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The granted access token.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("access_token")]
|
||||||
|
public string AccessToken { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The granted refresh token.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("refresh_token")]
|
||||||
|
public string RefreshToken { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// When it expires (ticks).
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("expires_in")]
|
||||||
|
public long ExpiresIn { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Granted token type.
|
||||||
|
/// </summary>
|
||||||
|
[JsonPropertyName("token_type")]
|
||||||
|
public string TokenType { get; set; }
|
||||||
|
}
|
|
@ -38,13 +38,13 @@ public class UserService : IUserService
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="UserService" /> class.
|
/// Initializes a new instance of the <see cref="UserService" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userRepository">Instance of <see cref="IUserRepository" />.</param>
|
|
||||||
/// <param name="cryptographyService">Instance of <see cref="ICryptographyService" />.</param>
|
|
||||||
/// <param name="userGroupService">Instance of <see cref="IUserGroupService" />.</param>
|
|
||||||
/// <param name="mapper">Instance of <see cref="IMapper" />.</param>
|
|
||||||
/// <param name="createUserValidator">Instance of <see cref="CreateUserValidator" />.</param>
|
/// <param name="createUserValidator">Instance of <see cref="CreateUserValidator" />.</param>
|
||||||
|
/// <param name="cryptographyService">Instance of <see cref="ICryptographyService" />.</param>
|
||||||
|
/// <param name="mapper">Instance of <see cref="IMapper" />.</param>
|
||||||
/// <param name="registrationConfig">Instance of <see cref="IOptions{RegistrationOptions}" />.</param>
|
/// <param name="registrationConfig">Instance of <see cref="IOptions{RegistrationOptions}" />.</param>
|
||||||
|
/// <param name="userGroupService">Instance of <see cref="IUserGroupService" />.</param>
|
||||||
/// <param name="transactionProvider">Instance of <see cref="ITransactionProvider" />.</param>
|
/// <param name="transactionProvider">Instance of <see cref="ITransactionProvider" />.</param>
|
||||||
|
/// <param name="userRepository">Instance of <see cref="IUserRepository" />.</param>
|
||||||
/// <param name="userProfileRepository">Instance of <see cref="IUserProfileRepository" />.</param>
|
/// <param name="userProfileRepository">Instance of <see cref="IUserProfileRepository" />.</param>
|
||||||
/// <param name="logger">Instance of <see cref="ILogger" />.</param>
|
/// <param name="logger">Instance of <see cref="ILogger" />.</param>
|
||||||
public UserService(
|
public UserService(
|
||||||
|
|
Loading…
Reference in a new issue