Skip to content

Commit

Permalink
Upgrade peer dep and update android
Browse files Browse the repository at this point in the history
  • Loading branch information
wslaghekke committed Sep 21, 2023
1 parent cfc7815 commit d8d8d48
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 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,11 @@ 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 @@ -9,6 +9,7 @@
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.argThat;

import android.content.Context;
import androidx.appcompat.app.AppCompatActivity;
Expand All @@ -20,6 +21,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,8 +104,12 @@ 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"))
.thenReturn(result);
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);
doNothing().when(pluginCallMock).resolve(jsObjectCaptor.capture());
Expand All @@ -114,9 +120,11 @@ 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

0 comments on commit d8d8d48

Please sign in to comment.