Skip to content

Commit

Permalink
Merge pull request #31 from recognizegroup/update-android-deps
Browse files Browse the repository at this point in the history
Upgrade peer dep and update android
  • Loading branch information
wslaghekke committed Sep 21, 2023
2 parents cfc7815 + 5eb629b commit 636623c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ if MsAuthPlugin.checkAppOpen(url: url, options: options) == true {
* (Android) In the `AndroidManifest.xml` file, append the following code within the `<application>` section:
```xml
<activity
android:name="com.microsoft.identity.client.BrowserTabActivity">
android:name="com.microsoft.identity.client.BrowserTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
Expand Down
3 changes: 2 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ allprojects {
dependencies {
implementation project(':capacitor-android')
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
implementation "com.microsoft.identity.client:msal:2.2.0"
implementation "com.microsoft.identity.client:msal:4.1.0"

testImplementation "org.json:json:20230227"
testImplementation "org.mockito:mockito-inline:5.2.0"
testImplementation "org.mockito:mockito-junit-jupiter:5.3.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
import com.getcapacitor.PluginMethod;
import com.getcapacitor.annotation.CapacitorPlugin;
import com.getcapacitor.annotation.Permission;
import com.microsoft.identity.client.AcquireTokenParameters;
import com.microsoft.identity.client.AuthenticationCallback;
import com.microsoft.identity.client.IAccount;
import com.microsoft.identity.client.IAuthenticationResult;
import com.microsoft.identity.client.ICurrentAccountResult;
import com.microsoft.identity.client.ISingleAccountPublicClientApplication;
import com.microsoft.identity.client.Prompt;
import com.microsoft.identity.client.*;
import com.microsoft.identity.client.exception.MsalException;
import java.io.File;
import java.io.FileWriter;
Expand Down Expand Up @@ -167,7 +161,9 @@ private void acquireToken(ISingleAccountPublicClientApplication context, List<St
if ((ca = context.getCurrentAccount()) != null && ca.getCurrentAccount() == null) {
this.acquireTokenInteractively(context, scopes, callback);
} else {
IAuthenticationResult silentAuthResult = context.acquireTokenSilent(scopes.toArray(new String[0]), authority);
AcquireTokenSilentParameters parameters =
(new AcquireTokenSilentParameters.Builder()).withScopes(scopes).fromAuthority(authority).build();
IAuthenticationResult silentAuthResult = context.acquireTokenSilent(parameters);
IAccount account = silentAuthResult.getAccount();

TokenResult tokenResult = new TokenResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.argThat;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
Expand All @@ -20,6 +20,7 @@
import com.microsoft.identity.client.ISingleAccountPublicClientApplication;
import com.microsoft.identity.client.exception.MsalException;
import java.io.File;
import java.util.List;
import org.json.JSONException;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -102,7 +103,13 @@ void loginExpectAcquireTokenSilent() throws JSONException, MsalException, Interr
ID_TOKEN,
new String[] { "mocked-scope", "openid", "profile" }
);
when(singleAccountPublicClientApplication.acquireTokenSilent(new String[] { "mocked-scope" }, "https://www.recognize.nl"))
when(
singleAccountPublicClientApplication.acquireTokenSilent(
argThat(
parameters -> parameters.getScopes().equals(List.of("mocked-scope")) && parameters.getAuthority().equals(AUTHORITY_URL)
)
)
)
.thenReturn(result);

ArgumentCaptor<JSObject> jsObjectCaptor = ArgumentCaptor.forClass(JSObject.class);
Expand All @@ -114,9 +121,10 @@ void loginExpectAcquireTokenSilent() throws JSONException, MsalException, Interr
// Verify
JSObject resolve = jsObjectCaptor.getValue();
assertEquals("access-token", resolve.getString("accessToken"));
assertEquals("" + ID_TOKEN, resolve.getString("idToken"));
assertEquals(ID_TOKEN, resolve.getString("idToken"));

verify(singleAccountPublicClientApplication).acquireTokenSilent(any(), eq(AUTHORITY_URL));
verify(singleAccountPublicClientApplication)
.acquireTokenSilent(argThat(parameters -> parameters.getAuthority().equals(AUTHORITY_URL)));
}

private void initializePluginCallMockWithDefaults(PluginCall pluginCallMock) throws JSONException {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 636623c

Please sign in to comment.