87 lines
2.6 KiB
C#
87 lines
2.6 KiB
C#
// <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;
|
|
using Astral.Core.Extensions;
|
|
using Astral.Services.Dtos;
|
|
|
|
namespace Astral.ApiServer.Models.Responses;
|
|
|
|
/// <summary>
|
|
/// OAuth Grant Request Response.
|
|
/// </summary>
|
|
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
|
public class TokenGrantResponseModel
|
|
{
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="TokenGrantResponseModel"/> class.
|
|
/// </summary>
|
|
/// <param name="sessionDto">Instance of <see cref="SessionDto"/> to create from.</param>
|
|
public TokenGrantResponseModel(SessionDto sessionDto)
|
|
{
|
|
AccessToken = sessionDto.AccessToken;
|
|
CreatedAt = ((DateTimeOffset)sessionDto.CreatedAt).ToUnixTimeSeconds();
|
|
ExpiresIn = ((DateTimeOffset)sessionDto.AccessTokenExpires).ToUnixTimeSeconds();
|
|
RefreshToken = sessionDto.RefreshToken;
|
|
Scope = sessionDto.Scope.ToString().ToLowerInvariant();
|
|
AccountId = sessionDto.UserId;
|
|
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")]
|
|
public Guid AccountId { get; set; }
|
|
|
|
/// <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; }
|
|
}
|