| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | |
|
| | 6 | | namespace Azure.Core |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// Represents an Azure service bearer access token with expiry information. |
| | 10 | | /// </summary> |
| | 11 | | public struct AccessToken |
| | 12 | | { |
| | 13 | | /// <summary> |
| | 14 | | /// Creates a new instance of <see cref="AccessToken"/> using the provided <paramref name="accessToken"/> and <p |
| | 15 | | /// </summary> |
| | 16 | | /// <param name="accessToken">The bearer access token value.</param> |
| | 17 | | /// <param name="expiresOn">The bearer access token expiry date.</param> |
| | 18 | | public AccessToken(string accessToken, DateTimeOffset expiresOn) |
| | 19 | | { |
| 68 | 20 | | Token = accessToken; |
| 68 | 21 | | ExpiresOn = expiresOn; |
| 68 | 22 | | } |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// Get the access token value. |
| | 26 | | /// </summary> |
| 68 | 27 | | public string Token { get; } |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// Gets the time when the provided token expires. |
| | 31 | | /// </summary> |
| 136 | 32 | | public DateTimeOffset ExpiresOn { get; } |
| | 33 | |
|
| | 34 | | /// <inheritdoc /> |
| | 35 | | public override bool Equals(object? obj) |
| | 36 | | { |
| 0 | 37 | | if (obj is AccessToken accessToken) |
| | 38 | | { |
| 0 | 39 | | return accessToken.ExpiresOn == ExpiresOn && accessToken.Token == Token; |
| | 40 | | } |
| | 41 | |
|
| 0 | 42 | | return false; |
| | 43 | | } |
| | 44 | |
|
| | 45 | | /// <inheritdoc /> |
| | 46 | | public override int GetHashCode() |
| | 47 | | { |
| 0 | 48 | | return Token.GetHashCode() ^ ExpiresOn.GetHashCode(); |
| | 49 | | } |
| | 50 | | } |
| | 51 | | } |