11// Copyright (c) Microsoft Corporation. All rights reserved.
22// Licensed under the MIT License.
33
4+ using System ;
45using System . Net . Http ;
56using System . Threading . Tasks ;
67using Microsoft . Identity . Client ;
@@ -12,6 +13,8 @@ namespace Microsoft.Identity.Test.Unit.PublicApiTests
1213 [ TestClass ]
1314 public class AdfsAcceptanceTests : TestBase
1415 {
16+ private const string AdfsScope = "https://arm.asz/.default" ;
17+
1518 // Possible authorities copied from: https://msazure.visualstudio.com/One/_search?action=contents&text=CanAcquireToken_UsingRefreshToken&type=code&lp=code-Project&filters=ProjectFilters%7BOne%7DRepositoryFilters%7BAzureStack-Services-Graph%7D&pageSize=25&result=DefaultCollection/One/AzureStack-Services-Graph/GBmain//src/Identity.Web.Tests/MsalTests.cs
1619 [ DataTestMethod ]
1720 [ DataRow ( "https://localhost:3001/adfs" ) ]
@@ -31,6 +34,37 @@ public async Task AdfsAuthorityVariants_WithAuthority_Async(string authority)
3134 await RunAuthCodeFlowAsync ( authority , useWithAdfsAuthority : false ) . ConfigureAwait ( false ) ;
3235 }
3336
37+ [ TestMethod ]
38+ public async Task AcquireTokenByUsernamePasswordAsync ( )
39+ {
40+ Uri authorityUri = new Uri ( "https://localhost:3001/adfs" ) ;
41+ using ( var httpManager = new MockHttpManager ( ) )
42+ {
43+ var builder = PublicClientApplicationBuilder
44+ . Create ( TestConstants . ClientId )
45+ . WithAuthority ( authorityUri )
46+ . WithHttpManager ( httpManager )
47+ . WithInstanceDiscovery ( false )
48+ . WithRedirectUri ( TestConstants . RedirectUri ) ;
49+
50+ var app = builder . Build ( ) ;
51+
52+ AddAdfsWithTenantIdMockHandler ( httpManager ) ;
53+
54+ var result = await app . AcquireTokenByUsernamePassword (
55+ TestConstants . s_scope ,
56+ TestConstants . Username ,
57+ TestConstants . DefaultPassword )
58+ . WithTenantIdFromAuthority ( authorityUri )
59+ . ExecuteAsync ( )
60+ . ConfigureAwait ( false ) ;
61+
62+ var account = await app . GetAccountAsync ( result . Account . HomeAccountId . Identifier ) . ConfigureAwait ( false ) ;
63+
64+ AssertAdfsResult ( result , account ) ;
65+ }
66+ }
67+
3468 private static async Task RunAuthCodeFlowAsync ( string authority , bool useWithAdfsAuthority )
3569 {
3670 using ( var httpManager = new MockHttpManager ( ) )
@@ -52,15 +86,15 @@ private static async Task RunAuthCodeFlowAsync(string authority, bool useWithAdf
5286
5387 AddAdfsWithTenantIdMockHandler ( httpManager ) ;
5488
55- var result = await app . AcquireTokenByAuthorizationCode ( new [ ] { "https://arm.asz/.default" } , "authcode" )
89+ var result = await app . AcquireTokenByAuthorizationCode ( new [ ] { AdfsScope } , "authcode" )
5690 . ExecuteAsync ( )
5791 . ConfigureAwait ( false ) ;
5892
5993 var account = await app . GetAccountAsync ( result . Account . HomeAccountId . Identifier ) . ConfigureAwait ( false ) ;
6094
6195 AssertAdfsResult ( result , account ) ;
6296
63- var result2 = await app . AcquireTokenSilent ( new [ ] { "https://arm.asz/.default" } , account )
97+ var result2 = await app . AcquireTokenSilent ( new [ ] { AdfsScope } , account )
6498 . ExecuteAsync ( )
6599 . ConfigureAwait ( false ) ;
66100
0 commit comments