-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
SharedTokenCacheCredentialBrokerOptions.cs
54 lines (47 loc) · 2.16 KB
/
SharedTokenCacheCredentialBrokerOptions.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using Microsoft.Identity.Client;
using Microsoft.Identity.Client.Broker;
namespace Azure.Identity.Broker
{
/// <summary>
/// Options to configure the <see cref="SharedTokenCacheCredential"/> to use the system authentication broker for silent authentication if available.
/// </summary>
public class SharedTokenCacheCredentialBrokerOptions : SharedTokenCacheCredentialOptions, IMsalPublicClientInitializerOptions
{
/// <summary>
/// Gets or sets whether Microsoft Account (MSA) passthrough is enabled.
/// </summary>
/// <value></value>
public bool? IsLegacyMsaPassthroughEnabled { get; set; }
/// <summary>
/// Gets or sets whether to authenticate with the default broker account instead of prompting the user with a login dialog.
/// </summary>
public bool UseDefaultBrokerAccount { get; set; }
/// <summary>
/// Initializes a new instance of <see cref="SharedTokenCacheCredentialBrokerOptions"/>.
/// </summary>
public SharedTokenCacheCredentialBrokerOptions()
: this(null)
{ }
/// <summary>
/// Initializes a new instance of <see cref="SharedTokenCacheCredentialBrokerOptions"/>.
/// </summary>
/// <param name="tokenCacheOptions">The <see cref="TokenCachePersistenceOptions"/> that will apply to the token cache used by this credential.</param>
public SharedTokenCacheCredentialBrokerOptions(TokenCachePersistenceOptions tokenCacheOptions)
: base(tokenCacheOptions)
{
}
Action<PublicClientApplicationBuilder> IMsalPublicClientInitializerOptions.BeforeBuildClient => AddBroker;
private void AddBroker(PublicClientApplicationBuilder builder)
{
var options = new BrokerOptions(BrokerOptions.OperatingSystems.Windows);
if (IsLegacyMsaPassthroughEnabled.HasValue)
{
options.MsaPassthrough = IsLegacyMsaPassthroughEnabled.Value;
}
builder.WithBroker(options);
}
}
}