Skip to content

Commit d6e3f97

Browse files
authored
Update plugin for capacitor v7 (#54)
* Update plugin for capacitor v7 * Fix build by making setup more like sample capacitorjs plugin * Update typescript * Fix android test * Lint test * Update Podfile.lock
1 parent 0af610c commit d6e3f97

File tree

15 files changed

+3204
-5797
lines changed

15 files changed

+3204
-5797
lines changed

.github/workflows/publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- uses: actions/checkout@v3
1111
- uses: actions/setup-node@v3
1212
with:
13-
node-version: '18'
13+
node-version: '22'
1414
- run: npm ci
1515
- run: npm set "//registry.npmjs.org/:_authToken" ${{ secrets.NPM_TOKEN }}
1616
- run: npm version --commit-hooks=false --allow-same-version=true ${GITHUB_REF##*/}

.github/workflows/validation.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- uses: actions/checkout@v3
1717
- uses: actions/setup-node@v3
1818
with:
19-
node-version: '18'
19+
node-version: '22'
2020
- run: npm install
2121
- run: npm run lint
2222

@@ -26,7 +26,7 @@ jobs:
2626
- uses: actions/checkout@v3
2727
- uses: actions/setup-node@v3
2828
with:
29-
node-version: '14'
29+
node-version: '22'
3030
- run: npm install
3131
- run: npm run verify:web
3232

@@ -36,12 +36,12 @@ jobs:
3636
- uses: actions/checkout@v3
3737
- uses: actions/setup-node@v3
3838
with:
39-
node-version: '18'
39+
node-version: '22'
4040
- name: Setup jdk
4141
uses: actions/setup-java@v3
4242
with:
4343
distribution: 'temurin'
44-
java-version: '17'
44+
java-version: '21'
4545
- run: npm install
4646
- run: npm run verify:android
4747

@@ -51,6 +51,6 @@ jobs:
5151
- uses: actions/checkout@v3
5252
- uses: actions/setup-node@v3
5353
with:
54-
node-version: '18'
54+
node-version: '22'
5555
- run: npm install
5656
- run: npm run verify:ios

.prettierignore

-2
This file was deleted.

RecognizebvCapacitorPluginMsauth.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
1111
s.author = package['author']
1212
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
1313
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14-
s.ios.deployment_target = '13.0'
14+
s.ios.deployment_target = '14.0'
1515
s.dependency 'Capacitor'
1616
s.dependency 'MSAL', '~>1.1'
1717
s.swift_version = '5.1'

android/build.gradle

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ ext {
33
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
44
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
55
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
6-
recognizebvMSALVersion = project.hasProperty("recognizebvMSALVersion") ? rootProject.ext.recognizebvMSALVersion : '5.4.0'
6+
recognizebvMSALVersion = project.hasProperty("recognizebvMSALVersion") ? rootProject.ext.recognizebvMSALVersion : '5.10.0'
77
}
88

99
buildscript {
@@ -12,18 +12,18 @@ buildscript {
1212
mavenCentral()
1313
}
1414
dependencies {
15-
classpath 'com.android.tools.build:gradle:8.2.1'
15+
classpath 'com.android.tools.build:gradle:8.7.2'
1616
}
1717
}
1818

1919
apply plugin: 'com.android.library'
2020

2121
android {
2222
namespace "nl.recognize.msauthplugin.capacitorpluginmsauth"
23-
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 33
23+
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
2424
defaultConfig {
25-
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
26-
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 33
25+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
26+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
2727
versionCode 1
2828
versionName "1.0"
2929
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -39,8 +39,8 @@ android {
3939
}
4040

4141
compileOptions {
42-
sourceCompatibility JavaVersion.VERSION_17
43-
targetCompatibility JavaVersion.VERSION_17
42+
sourceCompatibility JavaVersion.VERSION_21
43+
targetCompatibility JavaVersion.VERSION_21
4444
}
4545

4646
packagingOptions {

android/gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-all.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

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

+18-20
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,19 @@ public void login(final PluginCall call) {
7272
}
7373
}
7474

75-
this.acquireToken(
76-
context,
77-
call.getArray("scopes").toList(),
78-
prompt,
79-
tokenResult -> {
80-
if (tokenResult != null) {
81-
JSObject result = new JSObject();
82-
result.put("accessToken", tokenResult.getAccessToken());
83-
result.put("idToken", tokenResult.getIdToken());
84-
JSONArray scopes = new JSONArray(Arrays.asList(tokenResult.getScopes()));
85-
result.put("scopes", scopes);
86-
87-
call.resolve(result);
88-
} else {
89-
call.reject("Unable to obtain access token");
90-
}
75+
this.acquireToken(context, call.getArray("scopes").toList(), prompt, tokenResult -> {
76+
if (tokenResult != null) {
77+
JSObject result = new JSObject();
78+
result.put("accessToken", tokenResult.getAccessToken());
79+
result.put("idToken", tokenResult.getIdToken());
80+
JSONArray scopes = new JSONArray(Arrays.asList(tokenResult.getScopes()));
81+
result.put("scopes", scopes);
82+
83+
call.resolve(result);
84+
} else {
85+
call.reject("Unable to obtain access token");
9186
}
92-
);
87+
});
9388
} catch (Exception ex) {
9489
Logger.error("Unable to login: " + ex.getMessage(), ex);
9590
call.reject("Unable to fetch access token.");
@@ -139,14 +134,17 @@ protected String getAuthorityUrl(ISingleAccountPublicClientApplication context)
139134
return context.getConfiguration().getDefaultAuthority().getAuthorityURL().toString();
140135
}
141136

142-
private void acquireToken(ISingleAccountPublicClientApplication context, List<String> scopes, Prompt prompt, final TokenResultCallback callback)
143-
throws MsalException, InterruptedException {
137+
private void acquireToken(
138+
ISingleAccountPublicClientApplication context,
139+
List<String> scopes,
140+
Prompt prompt,
141+
final TokenResultCallback callback
142+
) throws MsalException, InterruptedException {
144143
String authority = getAuthorityUrl(context);
145144

146145
ICurrentAccountResult result = context.getCurrentAccount();
147146
if (result.getCurrentAccount() != null) {
148147
try {
149-
150148
Logger.info("Starting silent login flow");
151149
AcquireTokenSilentParameters.Builder builder = new AcquireTokenSilentParameters.Builder()
152150
.withScopes(scopes)

android/src/test/java/nl/recognize/msauthplugin/MsAuthPluginTest.java

+50-50
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
import com.getcapacitor.JSArray;
1616
import com.getcapacitor.JSObject;
1717
import com.getcapacitor.PluginCall;
18-
import com.microsoft.identity.client.IAccount;
19-
import com.microsoft.identity.client.IAuthenticationResult;
20-
import com.microsoft.identity.client.ISingleAccountPublicClientApplication;
18+
import com.microsoft.identity.client.*;
2119
import com.microsoft.identity.client.exception.MsalException;
2220
import java.io.File;
2321
import java.util.List;
@@ -59,38 +57,38 @@ class MsAuthPluginTest {
5957
void setUp() throws MsalException, InterruptedException {
6058
reset(mockedContext, mockedActivity, publicClientApplicationFactoryMock, singleAccountPublicClientApplication);
6159

62-
when(publicClientApplicationFactoryMock.createSingleAccountPublicClientApplication(any(Context.class), any(File.class)))
63-
.thenReturn(singleAccountPublicClientApplication);
60+
when(publicClientApplicationFactoryMock.createSingleAccountPublicClientApplication(any(Context.class), any(File.class))).thenReturn(
61+
singleAccountPublicClientApplication
62+
);
6463

65-
plugin =
66-
new MsAuthPlugin(publicClientApplicationFactoryMock) {
67-
final Context applicationContext = mock(Context.class);
64+
plugin = new MsAuthPlugin(publicClientApplicationFactoryMock) {
65+
final Context applicationContext = mock(Context.class);
6866

69-
@Override
70-
public Context getContext() {
71-
when(mockedContext.getApplicationContext()).thenReturn(applicationContext);
67+
@Override
68+
public Context getContext() {
69+
when(mockedContext.getApplicationContext()).thenReturn(applicationContext);
7270

73-
return mockedContext;
74-
}
71+
return mockedContext;
72+
}
7573

76-
@Override
77-
public AppCompatActivity getActivity() {
78-
lenient().when(applicationContext.getPackageName()).thenReturn("nl.recognize.project-x");
79-
lenient().when(mockedActivity.getApplicationContext()).thenReturn(applicationContext);
74+
@Override
75+
public AppCompatActivity getActivity() {
76+
lenient().when(applicationContext.getPackageName()).thenReturn("nl.recognize.project-x");
77+
lenient().when(mockedActivity.getApplicationContext()).thenReturn(applicationContext);
8078

81-
return mockedActivity;
82-
}
79+
return mockedActivity;
80+
}
8381

84-
@Override
85-
protected String getLogTag() {
86-
return "LogTag";
87-
}
82+
@Override
83+
protected String getLogTag() {
84+
return "LogTag";
85+
}
8886

89-
@Override
90-
protected String getAuthorityUrl(ISingleAccountPublicClientApplication context) {
91-
return AUTHORITY_URL;
92-
}
93-
};
87+
@Override
88+
protected String getAuthorityUrl(ISingleAccountPublicClientApplication context) {
89+
return AUTHORITY_URL;
90+
}
91+
};
9492
}
9593

9694
@Test
@@ -103,14 +101,16 @@ void loginExpectAcquireTokenSilent() throws JSONException, MsalException, Interr
103101
ID_TOKEN,
104102
new String[] { "mocked-scope", "openid", "profile" }
105103
);
104+
ICurrentAccountResult currentAccountResult = new CurrentAccountResult(result.getAccount(), null, true);
105+
when(singleAccountPublicClientApplication.getCurrentAccount()).thenReturn(currentAccountResult);
106+
106107
when(
107108
singleAccountPublicClientApplication.acquireTokenSilent(
108109
argThat(
109110
parameters -> parameters.getScopes().equals(List.of("mocked-scope")) && parameters.getAuthority().equals(AUTHORITY_URL)
110111
)
111112
)
112-
)
113-
.thenReturn(result);
113+
).thenReturn(result);
114114

115115
ArgumentCaptor<JSObject> jsObjectCaptor = ArgumentCaptor.forClass(JSObject.class);
116116
doNothing().when(pluginCallMock).resolve(jsObjectCaptor.capture());
@@ -123,31 +123,31 @@ void loginExpectAcquireTokenSilent() throws JSONException, MsalException, Interr
123123
assertEquals("access-token", resolve.getString("accessToken"));
124124
assertEquals(ID_TOKEN, resolve.getString("idToken"));
125125

126-
verify(singleAccountPublicClientApplication)
127-
.acquireTokenSilent(argThat(parameters -> parameters.getAuthority().equals(AUTHORITY_URL)));
126+
verify(singleAccountPublicClientApplication).acquireTokenSilent(
127+
argThat(parameters -> parameters.getAuthority().equals(AUTHORITY_URL))
128+
);
128129
}
129130

130131
private void initializePluginCallMockWithDefaults(PluginCall pluginCallMock) throws JSONException {
131132
when(pluginCallMock.getArray("scopes")).thenReturn(new JSArray(new String[] { "mocked-scope" }));
132-
when(pluginCallMock.getString(any()))
133-
.thenAnswer(
134-
(Answer<String>) invocation -> {
135-
switch (invocation.getArgument(0).toString()) {
136-
case "clientId":
137-
return CLIENT_ID;
138-
case "domainHint":
139-
return DOMAIN_HINT;
140-
case "tenant":
141-
return TENANT;
142-
case "keyHash":
143-
return KEY_HASH;
144-
case "authorityUrl":
145-
return AUTHORITY_URL;
146-
}
147-
148-
return null;
133+
when(pluginCallMock.getString(any())).thenAnswer(
134+
(Answer<String>) invocation -> {
135+
switch (invocation.getArgument(0).toString()) {
136+
case "clientId":
137+
return CLIENT_ID;
138+
case "domainHint":
139+
return DOMAIN_HINT;
140+
case "tenant":
141+
return TENANT;
142+
case "keyHash":
143+
return KEY_HASH;
144+
case "authorityUrl":
145+
return AUTHORITY_URL;
149146
}
150-
);
147+
148+
return null;
149+
}
150+
);
151151
when(pluginCallMock.getString("authorityType", AuthorityType.AAD.name())).thenReturn("AAD");
152152
}
153153

ios/Plugin.xcodeproj/project.pbxproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@
377377
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
378378
GCC_WARN_UNUSED_FUNCTION = YES;
379379
GCC_WARN_UNUSED_VARIABLE = YES;
380-
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
380+
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
381381
MTL_ENABLE_DEBUG_INFO = YES;
382382
ONLY_ACTIVE_ARCH = YES;
383383
SDKROOT = iphoneos;
@@ -431,7 +431,7 @@
431431
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
432432
GCC_WARN_UNUSED_FUNCTION = YES;
433433
GCC_WARN_UNUSED_VARIABLE = YES;
434-
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
434+
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
435435
MTL_ENABLE_DEBUG_INFO = NO;
436436
SDKROOT = iphoneos;
437437
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
@@ -454,7 +454,7 @@
454454
DYLIB_INSTALL_NAME_BASE = "@rpath";
455455
INFOPLIST_FILE = Plugin/Info.plist;
456456
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
457-
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
457+
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
458458
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)\n$(FRAMEWORK_SEARCH_PATHS)\n$(FRAMEWORK_SEARCH_PATHS)";
459459
ONLY_ACTIVE_ARCH = YES;
460460
PRODUCT_BUNDLE_IDENTIFIER = com.getcapacitor.Plugin;
@@ -479,7 +479,7 @@
479479
DYLIB_INSTALL_NAME_BASE = "@rpath";
480480
INFOPLIST_FILE = Plugin/Info.plist;
481481
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
482-
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
482+
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
483483
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks $(FRAMEWORK_SEARCH_PATHS)";
484484
ONLY_ACTIVE_ARCH = NO;
485485
PRODUCT_BUNDLE_IDENTIFIER = com.getcapacitor.Plugin;

ios/Podfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
platform :ios, '13.0'
1+
platform :ios, '14.0'
22

33
def capacitor_pods
44
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks

ios/Podfile.lock

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
PODS:
2-
- Capacitor (6.1.0):
2+
- Capacitor (7.0.1):
33
- CapacitorCordova
4-
- CapacitorCordova (6.1.0)
5-
- MSAL (1.1.19):
6-
- MSAL/app-lib (= 1.1.19)
7-
- MSAL/app-lib (1.1.19)
4+
- CapacitorCordova (7.0.1)
5+
- MSAL (1.7.0):
6+
- MSAL/app-lib (= 1.7.0)
7+
- MSAL/app-lib (1.7.0)
88

99
DEPENDENCIES:
1010
- "Capacitor (from `../node_modules/@capacitor/ios`)"
@@ -22,10 +22,10 @@ EXTERNAL SOURCES:
2222
:path: "../node_modules/@capacitor/ios"
2323

2424
SPEC CHECKSUMS:
25-
Capacitor: 187bd7847b6f71467015a20200a1a071be3e5f14
26-
CapacitorCordova: be703980ca797f847c3356f78fa175d21c8330c2
27-
MSAL: 0a4993a743aa45147c78c698e0412d00cb005c1a
25+
Capacitor: 23fff43571a4d1e3ee7d67b5a3588c6e757c2913
26+
CapacitorCordova: 63d476958d5022d76f197031e8b7ea3519988c64
27+
MSAL: 088bc688c1ce1a62f0d9c13905ddb31f8f1ac700
2828

29-
PODFILE CHECKSUM: f6274e5f60bf7be2dab2cca23d5c22f5d9f33c9e
29+
PODFILE CHECKSUM: 4d5ef135faa86f1882635355ccf295e635a7cdd2
3030

31-
COCOAPODS: 1.15.2
31+
COCOAPODS: 1.11.3

0 commit comments

Comments
 (0)