12
12
// limitations under the License.
13
13
// ----------------------------------------------------------------------------------
14
14
15
+ using System ;
16
+ using System . Collections . Generic ;
17
+ using System . Linq ;
18
+
15
19
using Azure . Identity ;
16
20
17
21
using Hyak . Common ;
20
24
using Microsoft . Azure . Commands . Common . Authentication . Abstractions . Extensions ;
21
25
using Microsoft . Azure . Commands . Common . Authentication . Abstractions . Interfaces ;
22
26
using Microsoft . Azure . Commands . Common . Authentication . Utilities ;
27
+ using Microsoft . Azure . Commands . Shared . Config ;
23
28
using Microsoft . Azure . Internal . Subscriptions ;
24
29
using Microsoft . Azure . Internal . Subscriptions . Models ;
30
+ using Microsoft . Azure . PowerShell . Common . Config ;
25
31
using Microsoft . Identity . Client ;
26
32
using Microsoft . Identity . Client . Broker ;
27
33
28
- using System ;
29
- using System . Collections . Generic ;
30
- using System . Linq ;
31
-
32
34
namespace Microsoft . Azure . Commands . Common . Authentication
33
35
{
34
36
public abstract class PowerShellTokenCacheProvider
@@ -53,14 +55,14 @@ public virtual void FlushTokenData()
53
55
_tokenCacheDataToFlush = null ;
54
56
}
55
57
56
- public virtual void ClearCache ( string authority = null )
58
+ public virtual void ClearCache ( )
57
59
{
58
60
}
59
61
60
- public bool TryRemoveAccount ( string accountId , string authority = null )
62
+ public bool TryRemoveAccount ( string accountId )
61
63
{
62
64
TracingAdapter . Information ( string . Format ( "[AuthenticationClientFactory] Calling GetAccountsAsync" ) ) ;
63
- var client = CreatePublicClient ( authority ) ;
65
+ var client = CreatePublicClient ( ) ;
64
66
var account = client . GetAccountsAsync ( )
65
67
. ConfigureAwait ( false ) . GetAwaiter ( ) . GetResult ( )
66
68
. FirstOrDefault ( a => string . Equals ( a . Username , accountId , StringComparison . OrdinalIgnoreCase ) ) ;
@@ -87,7 +89,7 @@ public IEnumerable<IAccount> ListAccounts(string authority = null)
87
89
{
88
90
TracingAdapter . Information ( string . Format ( "[PowerShellTokenCacheProvider] Calling GetAccountsAsync on {0}" , authority ?? "AzureCloud" ) ) ;
89
91
90
- return CreatePublicClient ( authority )
92
+ return CreatePublicClient ( authority : authority )
91
93
. GetAccountsAsync ( )
92
94
. ConfigureAwait ( false ) . GetAwaiter ( ) . GetResult ( ) ;
93
95
}
@@ -193,7 +195,18 @@ public virtual IPublicClientApplication CreatePublicClient(string authority, str
193
195
/// </summary>
194
196
public virtual IPublicClientApplication CreatePublicClient ( string authority = null )
195
197
{
196
- return CreatePublicClient ( authority , organizationTenant ) ;
198
+ var builder = PublicClientApplicationBuilder . Create ( Constants . PowerShellClientId ) ;
199
+ if ( AzConfigReader . IsWamEnabled ( authority ) )
200
+ {
201
+ builder = builder . WithBroker ( new BrokerOptions ( BrokerOptions . OperatingSystems . Windows ) ) ;
202
+ }
203
+ if ( ! string . IsNullOrEmpty ( authority ) )
204
+ {
205
+ builder . WithAuthority ( authority ) ;
206
+ }
207
+ var client = builder . Build ( ) ;
208
+ RegisterCache ( client ) ;
209
+ return client ;
197
210
}
198
211
199
212
public abstract TokenCachePersistenceOptions GetTokenCachePersistenceOptions ( ) ;
0 commit comments