// // Copyright (c) alveus.dev. All rights reserved. Licensed under the MIT License. // using System.Text.Json.Serialization; using Astral.Core.Extensions; using Astral.Services.Dtos; namespace Astral.ApiServer.Models.Responses; /// /// OAuth Grant Request Response. /// // ReSharper disable UnusedAutoPropertyAccessor.Global public class TokenGrantResponseModel { /// /// Initializes a new instance of the class. /// /// Instance of to create from. 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(); } /// /// The granted access token. /// [JsonPropertyName("access_token")] public string AccessToken { get; set; } /// /// When it expires (ticks). /// [JsonPropertyName("expires_in")] public long ExpiresIn { get; set; } /// /// The granted refresh token. /// [JsonPropertyName("refresh_token")] public string RefreshToken { get; set; } /// /// The session scope. /// [JsonPropertyName("scope")] public string Scope { get; set; } /// /// Granted token type. /// [JsonPropertyName("token_type")] public string TokenType { get; set; } /// /// When it was created (ticks). /// [JsonPropertyName("created_at")] public long CreatedAt { get; set; } /// /// The user's id. /// [JsonPropertyName("account_id")] public Guid AccountId { get; set; } /// /// The user's name. /// [JsonPropertyName("account_name")] public string AccountName { get; set; } /// /// The user's roles. /// [JsonPropertyName("account_roles")] public List AccountRoles { get; set; } }