1212import com .microsoft .identity .client .*;
1313import com .microsoft .identity .client .exception .MsalException ;
1414import com .microsoft .identity .client .exception .MsalUiRequiredException ;
15-
1615import java .io .File ;
1716import java .io .FileWriter ;
1817import java .io .IOException ;
@@ -124,9 +123,9 @@ private void acquireToken(ISingleAccountPublicClientApplication context, List<St
124123 try {
125124 Logger .info ("Starting silent login flow" );
126125 AcquireTokenSilentParameters .Builder builder = new AcquireTokenSilentParameters .Builder ()
127- .withScopes (scopes )
128- .fromAuthority (authority )
129- .forAccount (result .getCurrentAccount ());
126+ .withScopes (scopes )
127+ .fromAuthority (authority )
128+ .forAccount (result .getCurrentAccount ());
130129
131130 AcquireTokenSilentParameters parameters = builder .build ();
132131 IAuthenticationResult silentAuthResult = context .acquireTokenSilent (parameters );
@@ -147,44 +146,43 @@ private void acquireToken(ISingleAccountPublicClientApplication context, List<St
147146
148147 Logger .info ("Starting interactive login flow" );
149148 AcquireTokenParameters .Builder params = new AcquireTokenParameters .Builder ()
150- .startAuthorizationFromActivity (this .getActivity ())
151- .withScopes (scopes )
152- .withPrompt (Prompt .SELECT_ACCOUNT )
153- .withCallback (
154- new AuthenticationCallback () {
155- @ Override
156- public void onCancel () {
157- Logger .info ("Login cancelled" );
158- callback .tokenReceived (null );
159- }
160-
161- @ Override
162- public void onSuccess (IAuthenticationResult authenticationResult ) {
163- TokenResult tokenResult = new TokenResult ();
164-
165- IAccount account = authenticationResult .getAccount ();
166- tokenResult .setAccessToken (authenticationResult .getAccessToken ());
167- tokenResult .setIdToken (account .getIdToken ());
168- tokenResult .setScopes (authenticationResult .getScope ());
169-
170- callback .tokenReceived (tokenResult );
171- }
172-
173- @ Override
174- public void onError (MsalException ex ) {
175- Logger .error ("Unable to acquire token interactively" , ex );
176- callback .tokenReceived (null );
177- }
178- }
179- );
149+ .startAuthorizationFromActivity (this .getActivity ())
150+ .withScopes (scopes )
151+ .withPrompt (Prompt .SELECT_ACCOUNT )
152+ .withCallback (
153+ new AuthenticationCallback () {
154+ @ Override
155+ public void onCancel () {
156+ Logger .info ("Login cancelled" );
157+ callback .tokenReceived (null );
158+ }
159+
160+ @ Override
161+ public void onSuccess (IAuthenticationResult authenticationResult ) {
162+ TokenResult tokenResult = new TokenResult ();
163+
164+ IAccount account = authenticationResult .getAccount ();
165+ tokenResult .setAccessToken (authenticationResult .getAccessToken ());
166+ tokenResult .setIdToken (account .getIdToken ());
167+ tokenResult .setScopes (authenticationResult .getScope ());
168+
169+ callback .tokenReceived (tokenResult );
170+ }
171+
172+ @ Override
173+ public void onError (MsalException ex ) {
174+ Logger .error ("Unable to acquire token interactively" , ex );
175+ callback .tokenReceived (null );
176+ }
177+ }
178+ );
180179
181180 if (result .getCurrentAccount () != null ) {
182181 // Set loginHint otherwise MSAL throws an exception because of mismatched account
183182 params .withLoginHint (result .getCurrentAccount ().getUsername ());
184183 }
185184
186185 context .acquireToken (params .build ());
187-
188186 }
189187
190188 private ISingleAccountPublicClientApplication createContextFromPluginCall (PluginCall call )
@@ -207,8 +205,10 @@ private ISingleAccountPublicClientApplication createContextFromPluginCall(Plugin
207205 authorityType = AuthorityType .AAD ;
208206 } else if (AuthorityType .B2C .name ().equals (authorityTypeString )) {
209207 authorityType = AuthorityType .B2C ;
208+ } else if (AuthorityType .CIAM .name ().equals (authorityTypeString )) {
209+ authorityType = AuthorityType .CIAM ;
210210 } else {
211- call .reject ("Invalid authorityType specified. Only AAD and B2C are supported." );
211+ call .reject ("Invalid authorityType specified. Only AAD, B2C and CIAM are supported." );
212212 return null ;
213213 }
214214
@@ -244,6 +244,9 @@ private ISingleAccountPublicClientApplication createContext(
244244 authorityConfig .put ("authority_url" , authorityUrl );
245245 authorityConfig .put ("default" , "true" );
246246 break ;
247+ case CIAM :
248+ authorityConfig .put ("type" , AuthorityType .CIAM .name ()).put ("authority_url" , authorityUrl );
249+ break ;
247250 }
248251
249252 configFile .put ("client_id" , clientId );
0 commit comments