/
SharedTokenCacheCredentialOptions.cs
83 lines (70 loc) · 3.73 KB
/
SharedTokenCacheCredentialOptions.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Azure.Core;
namespace Azure.Identity
{
/// <summary>
/// Options to configure the <see cref="SharedTokenCacheCredential"/> authentication.
/// </summary>
public class SharedTokenCacheCredentialOptions : TokenCredentialOptions, ISupportsTokenCachePersistenceOptions, ISupportsDisableInstanceDiscovery
{
private string _tenantId;
private TokenCachePersistenceOptions _tokenCachePersistenceOptions;
internal static readonly TokenCachePersistenceOptions s_defaulTokenCachetPersistenceOptions = new TokenCachePersistenceOptions();
/// <summary>
/// The client id of the application registration used to authenticate users in the cache.
/// </summary>
public string ClientId { get; set; } = Constants.DeveloperSignOnClientId;
/// <summary>
/// Specifies the preferred authentication account username, or UPN, to be retrieved from the shared token cache for single sign on authentication with
/// development tools, in the case multiple accounts are found in the shared token.
/// </summary>
public string Username { get; set; }
/// <summary>
/// Specifies the tenant id of the preferred authentication account, to be retrieved from the shared token cache for single sign on authentication with
/// development tools, in the case multiple accounts are found in the shared token.
/// </summary>
public string TenantId
{
get { return _tenantId; }
set { _tenantId = Validations.ValidateTenantId(value, allowNull: true); }
}
/// <summary>
/// When set to true the <see cref="SharedTokenCacheCredential"/> can be used to authenticate to tenants other than the home tenant, requiring <see cref="Username"/> and <see cref="TenantId"/> also to be specified as well.
/// </summary>
public bool EnableGuestTenantAuthentication { get; set; }
/// <summary>
/// The <see cref="Identity.AuthenticationRecord"/> captured from a previous authentication with an interactive credential, such as the <see cref="InteractiveBrowserCredential"/> or <see cref="DeviceCodeCredential"/>.
/// </summary>
public AuthenticationRecord AuthenticationRecord { get; set; }
/// <summary>
/// Specifies the <see cref="TokenCachePersistenceOptions"/> to be used by the credential. Value cannot be null.
/// </summary>
public TokenCachePersistenceOptions TokenCachePersistenceOptions
{
get { return _tokenCachePersistenceOptions; }
set
{
Argument.AssertNotNull(value, nameof(value));
_tokenCachePersistenceOptions = value;
}
}
/// <summary>
/// Initializes a new instance of <see cref="SharedTokenCacheCredentialOptions"/>.
/// </summary>
public SharedTokenCacheCredentialOptions()
: this(null)
{ }
/// <summary>
/// Initializes a new instance of <see cref="SharedTokenCacheCredentialOptions"/>.
/// </summary>
/// <param name="tokenCacheOptions">The <see cref="TokenCachePersistenceOptions"/> that will apply to the token cache used by this credential.</param>
public SharedTokenCacheCredentialOptions(TokenCachePersistenceOptions tokenCacheOptions)
{
// if no tokenCacheOptions were specified we should use the default shared token cache
TokenCachePersistenceOptions = tokenCacheOptions ?? s_defaulTokenCachetPersistenceOptions;
}
/// <inheritdoc/>
public bool DisableInstanceDiscovery { get; set; }
}
}