Skip to content

Commit 65d19f5

Browse files
authored
fix for: The signed in account does not match with the provided account (#35)
* fix for: The signed in account does not match with the provided account * fix tests
1 parent 5d2776b commit 65d19f5

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ allprojects {
6363
dependencies {
6464
implementation project(':capacitor-android')
6565
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
66-
implementation "com.microsoft.identity.client:msal:4.1.0"
66+
implementation "com.microsoft.identity.client:msal:4.9.0"
6767

6868
testImplementation "org.json:json:20230227"
6969
testImplementation "org.mockito:mockito-inline:5.2.0"

android/src/main/java/nl/recognize/msauthplugin/MsAuthPlugin.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void login(final PluginCall call) {
6565
}
6666
);
6767
} catch (Exception ex) {
68-
Logger.error("Unable to login", ex);
68+
Logger.error("Unable to login: " + ex.getMessage(), ex);
6969
call.reject("Unable to fetch access token.");
7070
}
7171
}
@@ -159,10 +159,20 @@ private void acquireToken(ISingleAccountPublicClientApplication context, List<St
159159

160160
final ICurrentAccountResult ca;
161161
if ((ca = context.getCurrentAccount()) != null && ca.getCurrentAccount() == null) {
162+
Logger.info("Starting interactive login flow");
162163
this.acquireTokenInteractively(context, scopes, callback);
163164
} else {
164-
AcquireTokenSilentParameters parameters =
165-
(new AcquireTokenSilentParameters.Builder()).withScopes(scopes).fromAuthority(authority).build();
165+
Logger.info("Starting silent login flow");
166+
AcquireTokenSilentParameters.Builder builder = new AcquireTokenSilentParameters.Builder()
167+
.withScopes(scopes)
168+
.fromAuthority(authority);
169+
170+
if (ca != null && ca.getCurrentAccount() != null) {
171+
Logger.info("Silent login flow for current account");
172+
builder = builder.forAccount(ca.getCurrentAccount());
173+
}
174+
175+
AcquireTokenSilentParameters parameters = builder.build();
166176
IAuthenticationResult silentAuthResult = context.acquireTokenSilent(parameters);
167177
IAccount account = silentAuthResult.getAccount();
168178

0 commit comments

Comments
 (0)