您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
39 行
1.0 KiB
39 行
1.0 KiB
using System;
|
|
using Newtonsoft.Json;
|
|
using UnityEngine.Scripting;
|
|
|
|
namespace Unity.Services.Authentication.Models
|
|
{
|
|
class BaseJwt
|
|
{
|
|
[Preserve]
|
|
public BaseJwt() {}
|
|
|
|
[JsonProperty("exp")]
|
|
public int ExpirationTimeUnix;
|
|
[JsonProperty("iat")]
|
|
public int IssuedAtTimeUnix;
|
|
[JsonProperty("nbf")]
|
|
public int NotBeforeTimeUnix;
|
|
|
|
[JsonIgnore]
|
|
public DateTime ExpirationTime => ConvertTimestamp(ExpirationTimeUnix);
|
|
|
|
[JsonIgnore]
|
|
public DateTime IssuedAtTime => ConvertTimestamp(IssuedAtTimeUnix);
|
|
|
|
[JsonIgnore]
|
|
public DateTime NotBeforeTime => ConvertTimestamp(NotBeforeTimeUnix);
|
|
|
|
protected DateTime ConvertTimestamp(int timestamp)
|
|
{
|
|
if (timestamp != 0)
|
|
{
|
|
var dateTimeOffset = DateTimeOffset.FromUnixTimeSeconds(timestamp);
|
|
return dateTimeOffset.DateTime;
|
|
}
|
|
|
|
throw new Exception("Token does not contain a value for this timestamp.");
|
|
}
|
|
}
|
|
}
|