forked from PartnerCenterSamples/Commerce-API-DotNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAuthorizationToken.cs
49 lines (44 loc) · 1.52 KB
/
AuthorizationToken.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/********************************************************
* *
* Copyright (C) Microsoft. All rights reserved. *
* *
*********************************************************/
namespace Microsoft.Partner.CSP.Api.V1.Samples
{
using System;
public class AuthorizationToken
{
/// <summary>
/// Captures when the token expires
/// </summary>
private DateTime expiresOn { get; set; }
/// <summary>
/// Access token
/// </summary>
public string AccessToken { get; private set; }
/// <summary>
/// Constructor for getting an authorization token
/// </summary>
/// <param name="access_Token">access token</param>
/// <param name="expires_in">number of seconds the token is valid for</param>
public AuthorizationToken(string access_Token, long expires_in)
{
this.AccessToken = access_Token;
this.expiresOn = DateTime.UtcNow.AddSeconds(expires_in);
}
public AuthorizationToken(string access_Token, DateTimeOffset expires_on)
{
this.AccessToken = access_Token;
this.expiresOn = expires_on.DateTime;
}
/// <summary>
/// Returns true if the authorization token is near expiry
/// </summary>
/// <returns>true if the authorization token is near expiry</returns>
public bool IsNearExpiry()
{
//// if token is expiring in the next minute or expired, return true
return DateTime.UtcNow > this.expiresOn.AddMinutes(-1);
}
}
}