-
Notifications
You must be signed in to change notification settings - Fork 224
/
Copy pathClientAssertionProviderBase.cs
55 lines (49 loc) · 1.78 KB
/
ClientAssertionProviderBase.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
50
51
52
53
54
55
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Identity.Client;
namespace Microsoft.Identity.Web
{
/// <summary>
/// Description of a client assertion in the application configuration.
/// See https://aka.ms/ms-id-web/client-assertions.
/// </summary>
public abstract class ClientAssertionProviderBase
{
/// <summary>
/// Gets the Client assertion
/// </summary>
/// <param name="assertionRequestOptions"></param>
/// <returns></returns>
protected abstract Task<ClientAssertion> GetClientAssertionAsync(AssertionRequestOptions? assertionRequestOptions);
/// <summary>
/// Client assertion.
/// </summary>
private ClientAssertion? _clientAssertion;
/// <summary>
/// Get the signed assertion (and refreshes it if needed).
/// </summary>
/// <param name="assertionRequestOptions">Input object which is populated by the SDK.</param>
/// <returns>The signed assertion.</returns>
public async Task<string> GetSignedAssertionAsync(AssertionRequestOptions? assertionRequestOptions)
{
if (_clientAssertion == null || (Expiry != null && DateTimeOffset.Now > Expiry))
{
_clientAssertion = await GetClientAssertionAsync(assertionRequestOptions).ConfigureAwait(false);
}
return _clientAssertion.SignedAssertion;
}
/// <summary>
/// Expiry of the client assertion.
/// </summary>
public DateTimeOffset? Expiry
{
get
{
return _clientAssertion?.Expiry;
}
}
}
}