astral-api/Astral.ApiServer/Models/Responses/TokenGrantResponseModel.cs

88 lines
2.6 KiB
C#
Raw Permalink Normal View History

2024-12-15 17:06:14 +01:00
// <copyright file="TokenGrantResponseModel.cs" company="alveus.dev">
2024-12-14 17:31:17 +01:00
// Copyright (c) alveus.dev. All rights reserved. Licensed under the MIT License.
// </copyright>
using System.Text.Json.Serialization;
using Astral.Core.Extensions;
using Astral.Services.Dtos;
2024-12-15 17:06:14 +01:00
namespace Astral.ApiServer.Models.Responses;
2024-12-14 17:31:17 +01:00
/// <summary>
/// OAuth Grant Request Response.
/// </summary>
2024-12-15 17:06:14 +01:00
// ReSharper disable UnusedAutoPropertyAccessor.Global
public class TokenGrantResponseModel
2024-12-14 17:31:17 +01:00
{
/// <summary>
2024-12-15 17:06:14 +01:00
/// Initializes a new instance of the <see cref="TokenGrantResponseModel"/> class.
2024-12-14 17:31:17 +01:00
/// </summary>
/// <param name="sessionDto">Instance of <see cref="SessionDto"/> to create from.</param>
2024-12-15 17:06:14 +01:00
public TokenGrantResponseModel(SessionDto sessionDto)
2024-12-14 17:31:17 +01:00
{
AccessToken = sessionDto.AccessToken;
2024-12-15 17:06:14 +01:00
CreatedAt = ((DateTimeOffset)sessionDto.CreatedAt).ToUnixTimeSeconds();
ExpiresIn = ((DateTimeOffset)sessionDto.AccessTokenExpires).ToUnixTimeSeconds();
2024-12-14 17:31:17 +01:00
RefreshToken = sessionDto.RefreshToken;
Scope = sessionDto.Scope.ToString().ToLowerInvariant();
2024-12-14 18:48:03 +01:00
AccountId = sessionDto.UserId;
2024-12-14 17:31:17 +01:00
AccountName = sessionDto.UserName;
TokenType = "Bearer";
AccountRoles = sessionDto.Role.GetAccessibleRoles().Select(role => role.ToString().ToLowerInvariant()).ToList();
}
/// <summary>
/// The granted access token.
/// </summary>
[JsonPropertyName("access_token")]
public string AccessToken { get; set; }
/// <summary>
/// When it expires (ticks).
/// </summary>
[JsonPropertyName("expires_in")]
public long ExpiresIn { get; set; }
/// <summary>
/// The granted refresh token.
/// </summary>
[JsonPropertyName("refresh_token")]
public string RefreshToken { get; set; }
/// <summary>
/// The session scope.
/// </summary>
[JsonPropertyName("scope")]
public string Scope { get; set; }
/// <summary>
/// Granted token type.
/// </summary>
[JsonPropertyName("token_type")]
public string TokenType { get; set; }
/// <summary>
/// When it was created (ticks).
/// </summary>
[JsonPropertyName("created_at")]
public long CreatedAt { get; set; }
/// <summary>
/// The user's id.
/// </summary>
[JsonPropertyName("account_id")]
2024-12-14 18:48:03 +01:00
public Guid AccountId { get; set; }
2024-12-14 17:31:17 +01:00
/// <summary>
/// The user's name.
/// </summary>
[JsonPropertyName("account_name")]
public string AccountName { get; set; }
/// <summary>
/// The user's roles.
/// </summary>
[JsonPropertyName("account_roles")]
public List<string> AccountRoles { get; set; }
}