@@ -39,8 +39,7 @@ AuthenticationResult execute() throws Exception {
3939 }
4040
4141 if (authGrant instanceof OAuthAuthorizationGrant ) {
42- msalRequest .msalAuthorizationGrant =
43- processPasswordGrant ((OAuthAuthorizationGrant ) authGrant );
42+ processPasswordGrant ((OAuthAuthorizationGrant ) authGrant );
4443 }
4544
4645 if (authGrant instanceof IntegratedWindowsAuthorizationGrant ) {
@@ -74,39 +73,32 @@ private boolean IsUiRequiredCacheSupported() {
7473 clientApplication instanceof PublicClientApplication ;
7574 }
7675
77- private OAuthAuthorizationGrant processPasswordGrant (
78- OAuthAuthorizationGrant authGrant ) throws Exception {
79-
80- if (!(authGrant .toParameters ().get (GrantConstants .GRANT_TYPE_PARAMETER ).get (0 ).equals (GrantConstants .PASSWORD ))) {
81- return authGrant ;
82- }
76+ private void processPasswordGrant (OAuthAuthorizationGrant authGrant ) throws Exception {
8377
84- if (msalRequest .application ().authenticationAuthority .authorityType != AuthorityType .AAD ) {
85- return authGrant ;
78+ //Additional processing is only needed if it's a password grant with a non-AAD authority
79+ if (!(authGrant .getParamValue (GrantConstants .GRANT_TYPE_PARAMETER ).equals (GrantConstants .PASSWORD ))
80+ || msalRequest .application ().authenticationAuthority .authorityType != AuthorityType .AAD ) {
81+ return ;
8682 }
8783
8884 UserDiscoveryResponse userDiscoveryResponse = UserDiscoveryRequest .execute (
89- this .clientApplication .authenticationAuthority .getUserRealmEndpoint (authGrant .toParameters (). get ( "username" ). get ( 0 )),
85+ this .clientApplication .authenticationAuthority .getUserRealmEndpoint (authGrant .getParamValue ( GrantConstants . USERNAME_PARAMETER )),
9086 msalRequest .headers ().getReadonlyHeaderMap (),
9187 msalRequest .requestContext (),
9288 this .clientApplication .serviceBundle ());
9389
9490 if (userDiscoveryResponse .isAccountFederated ()) {
9591 WSTrustResponse response = WSTrustRequest .execute (
9692 userDiscoveryResponse .federationMetadataUrl (),
97- authGrant .toParameters (). get ( GrantConstants .USERNAME_PARAMETER ). get ( 0 ),
98- authGrant .toParameters (). get ( GrantConstants .PASSWORD_PARAMETER ). get ( 0 ),
93+ authGrant .getParamValue ( GrantConstants .USERNAME_PARAMETER ),
94+ authGrant .getParamValue ( GrantConstants .PASSWORD_PARAMETER ),
9995 userDiscoveryResponse .cloudAudienceUrn (),
10096 msalRequest .requestContext (),
10197 this .clientApplication .serviceBundle (),
10298 this .clientApplication .logPii ());
10399
104- Map <String , List <String >> params = getSAMLAuthGrantParameters (response );
105- params .putAll (authGrant .toParameters ());
106-
107- authGrant = new OAuthAuthorizationGrant (params , null );
100+ authGrant .addAndReplaceParams (getSAMLAuthGrantParameters (response ));
108101 }
109- return authGrant ;
110102 }
111103
112104 private Map <String , List <String >> getSAMLAuthGrantParameters (WSTrustResponse response ) {
0 commit comments