Skip to content

Commit

Permalink
fix for: The signed in account does not match with the provided accou…
Browse files Browse the repository at this point in the history
…nt (#35)

* fix for: The signed in account does not match with the provided account

* fix tests
  • Loading branch information
steindekker authored Oct 19, 2023
1 parent 5d2776b commit 65d19f5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ allprojects {
dependencies {
implementation project(':capacitor-android')
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
implementation "com.microsoft.identity.client:msal:4.1.0"
implementation "com.microsoft.identity.client:msal:4.9.0"

testImplementation "org.json:json:20230227"
testImplementation "org.mockito:mockito-inline:5.2.0"
Expand Down
16 changes: 13 additions & 3 deletions android/src/main/java/nl/recognize/msauthplugin/MsAuthPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void login(final PluginCall call) {
}
);
} catch (Exception ex) {
Logger.error("Unable to login", ex);
Logger.error("Unable to login: " + ex.getMessage(), ex);
call.reject("Unable to fetch access token.");
}
}
Expand Down Expand Up @@ -159,10 +159,20 @@ private void acquireToken(ISingleAccountPublicClientApplication context, List<St

final ICurrentAccountResult ca;
if ((ca = context.getCurrentAccount()) != null && ca.getCurrentAccount() == null) {
Logger.info("Starting interactive login flow");
this.acquireTokenInteractively(context, scopes, callback);
} else {
AcquireTokenSilentParameters parameters =
(new AcquireTokenSilentParameters.Builder()).withScopes(scopes).fromAuthority(authority).build();
Logger.info("Starting silent login flow");
AcquireTokenSilentParameters.Builder builder = new AcquireTokenSilentParameters.Builder()
.withScopes(scopes)
.fromAuthority(authority);

if (ca != null && ca.getCurrentAccount() != null) {
Logger.info("Silent login flow for current account");
builder = builder.forAccount(ca.getCurrentAccount());
}

AcquireTokenSilentParameters parameters = builder.build();
IAuthenticationResult silentAuthResult = context.acquireTokenSilent(parameters);
IAccount account = silentAuthResult.getAccount();

Expand Down

0 comments on commit 65d19f5

Please sign in to comment.