aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/DTO/TokenResponse.cs
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-02-13 07:58:15 -0600
committerJP Dillingham <jpdillingham@gmail.com>2021-02-13 07:58:15 -0600
commit936ed099a6e5258f9fd5a5ac026afc0630359b98 (patch)
treef406e1f1b9fc29391e471c65b708ba6d94b72027 /src/slskd/DTO/TokenResponse.cs
parent87f024fa2561f751fc26c129bfaa373a966f1c67 (diff)
downloadslskd-936ed099a6e5258f9fd5a5ac026afc0630359b98.tar.gz
move controllers and DTOs to API namespace
Diffstat (limited to 'src/slskd/DTO/TokenResponse.cs')
-rw-r--r--src/slskd/DTO/TokenResponse.cs50
1 files changed, 0 insertions, 50 deletions
diff --git a/src/slskd/DTO/TokenResponse.cs b/src/slskd/DTO/TokenResponse.cs
deleted file mode 100644
index fb1b81ee..00000000
--- a/src/slskd/DTO/TokenResponse.cs
+++ /dev/null
@@ -1,50 +0,0 @@
-namespace slskd.DTO
-{
- using System;
- using System.IdentityModel.Tokens.Jwt;
- using System.Linq;
- using System.Security.Claims;
- using System.Text.Json.Serialization;
- using Microsoft.AspNetCore.Authentication.JwtBearer;
-
- public class TokenResponse
- {
- public TokenResponse(JwtSecurityToken jwtSecurityToken)
- {
- JwtSecurityToken = jwtSecurityToken;
- }
-
- [JsonIgnore]
- private JwtSecurityToken JwtSecurityToken { get; }
-
- /// <summary>
- /// Gets the Access Token string.
- /// </summary>
- public string Token => new JwtSecurityTokenHandler().WriteToken(JwtSecurityToken);
-
- /// <summary>
- /// Gets the time at which the Access Token expires.
- /// </summary>
- public long Expires => ((DateTimeOffset)JwtSecurityToken.ValidTo).ToUnixTimeSeconds();
-
- /// <summary>
- /// Gets the time at which the Access Token was issued.
- /// </summary>
- public long Issued => ((DateTimeOffset)JwtSecurityToken.ValidFrom).ToUnixTimeSeconds();
-
- /// <summary>
- /// Gets the value of the Name claim from the Access Token.
- /// </summary>
- public string Name => JwtSecurityToken.Claims.Where(c => c.Type == ClaimTypes.Name).SingleOrDefault().Value;
-
- /// <summary>
- /// Gets the value of the Not Before claim from the Access Token.
- /// </summary>
- public long NotBefore => long.Parse(JwtSecurityToken.Claims.Where(c => c.Type == "nbf").SingleOrDefault().Value);
-
- /// <summary>
- /// Gets the Token type.
- /// </summary>
- public string TokenType => JwtBearerDefaults.AuthenticationScheme;
- }
-} \ No newline at end of file