// // Copyright (c) alveus.dev. All rights reserved. Licensed under the MIT License. // using System.Text.Json.Serialization; using Astral.ApiServer.Models.Common; using Astral.Core.Extensions; using Astral.Services.Dtos; namespace Astral.ApiServer.Models; /// /// OAuth Grant Request Response. /// public class TokenGrantResultModel : ResultModel { /// /// Initializes a new instance of the class. /// public TokenGrantResultModel() { } /// /// Initializes a new instance of the class. /// /// Instance of to create from. public TokenGrantResultModel(SessionDto sessionDto) { Success = true; AccessToken = sessionDto.AccessToken; CreatedAt = sessionDto.CreatedAt.Ticks; ExpiresIn = sessionDto.AccessTokenExpires.Ticks; RefreshToken = sessionDto.RefreshToken; Scope = sessionDto.Scope.ToString().ToLowerInvariant(); AccountId = sessionDto.UserId.ToString(); 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 string 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; } }