@frontegg/ionic-capacitor 1.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/FronteggIonicCapacitor.podspec +1 -1
- package/README.md +244 -31
- package/android/build.gradle +2 -2
- package/android/src/main/java/com/frontegg/ionic/FronteggNativePlugin.java +82 -43
- package/android/src/main/java/com/frontegg/ionic/Parser.java +26 -0
- package/dist/esm/definitions.d.ts +53 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/frontegg.service.d.ts +15 -1
- package/dist/esm/frontegg.service.js +30 -2
- package/dist/esm/frontegg.service.js.map +1 -1
- package/dist/esm/observables.d.ts +1 -1
- package/dist/esm/web.d.ts +11 -2
- package/dist/esm/web.js +9 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +39 -2
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +39 -2
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/FronteggNativePlugin.m +1 -0
- package/ios/Plugin/FronteggNativePlugin.swift +86 -5
- package/package.json +1 -1
|
@@ -13,7 +13,7 @@ Pod::Spec.new do |s|
|
|
|
13
13
|
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
14
|
s.ios.deployment_target = '14.0'
|
|
15
15
|
s.dependency 'Capacitor'
|
|
16
|
-
s.dependency "FronteggSwift", "1.
|
|
16
|
+
s.dependency "FronteggSwift", "1.2.4"
|
|
17
17
|
s.swift_version = '5.1'
|
|
18
18
|
s.pod_target_xcconfig = {
|
|
19
19
|
'CODE_SIGNING_ALLOWED' => 'YES'
|
package/README.md
CHANGED
|
@@ -7,25 +7,29 @@ features for the product-led era.
|
|
|
7
7
|
|
|
8
8
|
- [Project Requirements](#project-requirements)
|
|
9
9
|
- [Getting Started](#getting-started)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
- [Prepare Frontegg workspace](#prepare-frontegg-workspace)
|
|
11
|
+
- [Setup Hosted Login](#setup-hosted-login)
|
|
12
|
+
- [Add frontegg package to the project](#add-frontegg-package-to-the-project)
|
|
13
|
+
- [Configure your application](#configure-your-application)
|
|
14
14
|
- [Setup iOS Project](#setup-ios-project)
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
- [Create Frontegg plist file](#create-frontegg-plist-file)
|
|
16
|
+
- [Config iOS associated domain](#config-ios-associated-domain)
|
|
17
17
|
- [Setup Android Project](#setup-android-project)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
- [Set minimum SDK version](#set-minimum-sdk-version)
|
|
19
|
+
- [Configure build config fields](#configure-build-config-fields)
|
|
20
|
+
- [Config Android AssetLinks](#config-ios-associated-domain)
|
|
21
21
|
- [Angular Usages](#angular-usages)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
- [Integrate Frontegg](#integrate-frontegg)
|
|
23
|
+
- [Protect Routes](#protect-routes)
|
|
24
|
+
- [Get Logged In User](#get-logged-in-user)
|
|
25
|
+
- [Switch Tenant](#switch-tenant)
|
|
26
26
|
- [Embedded Webview vs Hosted](#embedded-webview-vs-hosted)
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
- [Enable hosted webview in iOS Platform](#enable-hosted-webview-in-ios-platform)
|
|
28
|
+
- [Enable hosted webview in Android Platform](#enable-hosted-webview-in-android-platform)
|
|
29
|
+
- [Multi-Region Support](#multi-region-support)
|
|
30
|
+
- [Step 1: Add regions to your Frontegg configuration](#step-1-add-regions-to-your-frontegg-configuration)
|
|
31
|
+
- [Setup multi-region support for iOS Platform](#setup-multi-region-support-for-ios-platform)
|
|
32
|
+
- [Setup multi-region support for Android Platform](#setup-multi-region-support-for-android-platform)
|
|
29
33
|
|
|
30
34
|
## Project Requirements
|
|
31
35
|
|
|
@@ -94,6 +98,13 @@ yarn add @frontegg/react-native
|
|
|
94
98
|
android: {
|
|
95
99
|
path: 'android',
|
|
96
100
|
},
|
|
101
|
+
|
|
102
|
+
plugins: {
|
|
103
|
+
FronteggNative:{
|
|
104
|
+
baseUrl: 'https://{FRONTEGG_DOMAIN_HOST.com}',
|
|
105
|
+
clientId: '{FRONTEGG_CLIENT_ID}',
|
|
106
|
+
}
|
|
107
|
+
}
|
|
97
108
|
};
|
|
98
109
|
|
|
99
110
|
export default config;
|
|
@@ -127,10 +138,8 @@ To setup your SwiftUI application to communicate with Frontegg.
|
|
|
127
138
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
128
139
|
<plist version="1.0">
|
|
129
140
|
<dict>
|
|
130
|
-
<key>
|
|
131
|
-
<
|
|
132
|
-
<key>clientId</key>
|
|
133
|
-
<string>[CLIENT_ID_FROM_PREVIOUS_STEP]</string>
|
|
141
|
+
<key>lateInit</key>
|
|
142
|
+
<true/>
|
|
134
143
|
</dict>
|
|
135
144
|
</plist>
|
|
136
145
|
```
|
|
@@ -234,9 +243,6 @@ android {
|
|
|
234
243
|
"frontegg_domain" : fronteggDomain,
|
|
235
244
|
"frontegg_client_id": fronteggClientId
|
|
236
245
|
]
|
|
237
|
-
|
|
238
|
-
buildConfigField "String", 'FRONTEGG_DOMAIN', "\"$fronteggDomain\""
|
|
239
|
-
buildConfigField "String", 'FRONTEGG_CLIENT_ID', "\"$fronteggClientId\""
|
|
240
246
|
}
|
|
241
247
|
|
|
242
248
|
|
|
@@ -429,7 +435,7 @@ import { FronteggService } from '@frontegg/ionic-capacitor';
|
|
|
429
435
|
2. Open the `src/app-routing.module.ts` file and add wrap the app routes with loadChildren and apply CanActivate guard:
|
|
430
436
|
|
|
431
437
|
```typescript
|
|
432
|
-
import { AuthGuard } from './auth.
|
|
438
|
+
import { AuthGuard } from './auth.guard';
|
|
433
439
|
|
|
434
440
|
const routes: Routes = [
|
|
435
441
|
{
|
|
@@ -516,8 +522,8 @@ Frontegg SDK supports two authentication methods:
|
|
|
516
522
|
|
|
517
523
|
- Embedded Webview
|
|
518
524
|
- Hosted Webview
|
|
519
|
-
|
|
520
|
-
|
|
525
|
+
- `iOS`: ASWebAuthenticationSession
|
|
526
|
+
- `Android`: Custom Chrome Tab
|
|
521
527
|
|
|
522
528
|
By default, Frontegg SDK will use Embedded Webview.
|
|
523
529
|
|
|
@@ -530,14 +536,11 @@ To use ASWebAuthenticationSession you have to set `embeddedMode` to `NO` in `Fro
|
|
|
530
536
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN">
|
|
531
537
|
<plist version="1.0">
|
|
532
538
|
<dict>
|
|
533
|
-
<key>
|
|
534
|
-
<
|
|
535
|
-
<key>clientId</key>
|
|
536
|
-
<string>[CLIENT_ID_FROM_PREVIOUS_STEP]</string>
|
|
537
|
-
|
|
539
|
+
<key>lateInit</key>
|
|
540
|
+
<true/>
|
|
538
541
|
<!-- START -->
|
|
539
542
|
<key>embeddedMode</key>
|
|
540
|
-
<
|
|
543
|
+
<false/>
|
|
541
544
|
<!-- END -->
|
|
542
545
|
</dict>
|
|
543
546
|
</plist>
|
|
@@ -564,3 +567,213 @@ the application manifest:
|
|
|
564
567
|
</application>
|
|
565
568
|
</manifest>
|
|
566
569
|
```
|
|
570
|
+
|
|
571
|
+
## Multi-Region Support
|
|
572
|
+
|
|
573
|
+
This guide outlines the steps to configure your Ionic application to support multiple regions.
|
|
574
|
+
|
|
575
|
+
### Step 1: Add regions to your Frontegg configuration
|
|
576
|
+
|
|
577
|
+
Add `region` to your Frontegg configuration in `capacitor.config.ts` file:
|
|
578
|
+
|
|
579
|
+
Find example code in [example/capacitor.config.ts](example/capacitor.config.ts) file.
|
|
580
|
+
|
|
581
|
+
```typescript
|
|
582
|
+
import { CapacitorConfig } from '@capacitor/cli';
|
|
583
|
+
|
|
584
|
+
const config: CapacitorConfig = {
|
|
585
|
+
/*...*/
|
|
586
|
+
plugins: {
|
|
587
|
+
|
|
588
|
+
/*...*/
|
|
589
|
+
|
|
590
|
+
FronteggNative: {
|
|
591
|
+
|
|
592
|
+
/** Remove baseUrl and clientId from here */
|
|
593
|
+
// baseUrl: 'https://{FRONTEGG_DOMAIN_HOST.com}',
|
|
594
|
+
// clientId: '{FRONTEGG_CLIENT_ID}',
|
|
595
|
+
|
|
596
|
+
regions: [ {
|
|
597
|
+
key: 'REGION_1_KEY',
|
|
598
|
+
baseUrl: 'https://region1.forntegg.com',
|
|
599
|
+
clientId: 'REGION_1_CLIEND_ID',
|
|
600
|
+
}, {
|
|
601
|
+
key: 'REGION_2_KEY',
|
|
602
|
+
baseUrl: 'https://region2.forntegg.com',
|
|
603
|
+
clientId: 'REGION_2_CLIEND_ID',
|
|
604
|
+
} ]
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
export default config;
|
|
610
|
+
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
### Step 2: Create region guard service
|
|
614
|
+
|
|
615
|
+
Create region guard service, this guard will prevent application init if region not selected,
|
|
616
|
+
and checks if specific region selected by getting the native state from the Frontegg SDK.
|
|
617
|
+
If the region not exists, the guard will redirect to region selector page.
|
|
618
|
+
|
|
619
|
+
Find example code in [example/src/app/region.guard.ts](example/src/app/region.guard.ts) file.
|
|
620
|
+
|
|
621
|
+
```typescript
|
|
622
|
+
import { CanActivateFn, Router } from '@angular/router';
|
|
623
|
+
import { Inject, Injectable } from '@angular/core';
|
|
624
|
+
import { FronteggService } from '@frontegg/ionic-capacitor';
|
|
625
|
+
|
|
626
|
+
@Injectable({
|
|
627
|
+
providedIn: 'root'
|
|
628
|
+
})
|
|
629
|
+
export class RegionGuard {
|
|
630
|
+
constructor(@Inject('Frontegg') private fronteggService: FronteggService, private router: Router) {
|
|
631
|
+
/**
|
|
632
|
+
* Listens to $isAuthenticated changes
|
|
633
|
+
* Reload the page to trigger canActivate function again
|
|
634
|
+
*/
|
|
635
|
+
this.fronteggService.$selectedRegion.subscribe(async () => {
|
|
636
|
+
window.location.reload()
|
|
637
|
+
});
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
canActivate: CanActivateFn = async () => {
|
|
641
|
+
const { isRegional } = await this.fronteggService.getConstants();
|
|
642
|
+
const nativeState = await this.fronteggService.getNativeState()
|
|
643
|
+
|
|
644
|
+
if (!isRegional || nativeState.selectedRegion != null) {
|
|
645
|
+
/**
|
|
646
|
+
* region already selected, activate navigation
|
|
647
|
+
*/
|
|
648
|
+
return true
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* region not selected, redirect to region selector page
|
|
653
|
+
*/
|
|
654
|
+
return this.router.navigate([ '/select-region' ])
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
```
|
|
658
|
+
|
|
659
|
+
### Step 3: Add region guard to application router
|
|
660
|
+
|
|
661
|
+
Find example code in [example/src/app/app-routing.module.ts](example/src/app/app-routing.module.ts) file.
|
|
662
|
+
|
|
663
|
+
```typescript
|
|
664
|
+
const routes: Routes = [
|
|
665
|
+
{
|
|
666
|
+
path: '',
|
|
667
|
+
canActivate: [ RegionGuard ],
|
|
668
|
+
children: [
|
|
669
|
+
/**
|
|
670
|
+
* Wrap all routes with region guard
|
|
671
|
+
* to redirect to region selector page
|
|
672
|
+
* if region not exists
|
|
673
|
+
*/
|
|
674
|
+
{
|
|
675
|
+
path: '',
|
|
676
|
+
canActivate: [ AuthGuard ],
|
|
677
|
+
loadChildren: () => import('./tabs/tabs.module').then(m => m.TabsPageModule)
|
|
678
|
+
},
|
|
679
|
+
]
|
|
680
|
+
}, {
|
|
681
|
+
/**
|
|
682
|
+
* Add region selector page
|
|
683
|
+
* to select region if not exists
|
|
684
|
+
*/
|
|
685
|
+
path: 'select-region',
|
|
686
|
+
component: SelectRegionComponent
|
|
687
|
+
}
|
|
688
|
+
];
|
|
689
|
+
```
|
|
690
|
+
|
|
691
|
+
### Step 4: Setup multi-region support for iOS Platform
|
|
692
|
+
|
|
693
|
+
Following guide outlines the steps to configure iOS application to support multiple regions.
|
|
694
|
+
|
|
695
|
+
**First, Adjust Your Frontegg.plist File for Multiple Regions:**
|
|
696
|
+
- Remove the existing `baseUrl` and `clientId` keys.
|
|
697
|
+
- Add a new boolean property, `lateInit`, and set it to `true`.
|
|
698
|
+
|
|
699
|
+
Example Frontegg.plist Structure:
|
|
700
|
+
```xml
|
|
701
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
702
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
703
|
+
<plist version="1.0">
|
|
704
|
+
<dict>
|
|
705
|
+
<key>lateInit</key>
|
|
706
|
+
<true/>
|
|
707
|
+
</dict>
|
|
708
|
+
</plist>
|
|
709
|
+
```
|
|
710
|
+
**Secondly, Add Associated Domains for Each Region:**
|
|
711
|
+
|
|
712
|
+
Configure the associated domains for each region in your application's settings. This step is crucial for correct API routing and authentication.
|
|
713
|
+
Follow the guide [Config iOS Associated Domain](#config-ios-associated-domain) to add your iOS associated domain to your Frontegg application.
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
### Step 5: Setup multi-region support for Android Platform
|
|
717
|
+
|
|
718
|
+
Following guide outlines the steps to configure Android application to support multiple regions.
|
|
719
|
+
|
|
720
|
+
**First, Modify the Build.gradle file**
|
|
721
|
+
- remove buildConfigFields from your build.gradle file: `legacy`
|
|
722
|
+
|
|
723
|
+
```groovy
|
|
724
|
+
|
|
725
|
+
android {
|
|
726
|
+
// remove this lines:
|
|
727
|
+
// buildConfigField "String", 'FRONTEGG_DOMAIN', "\"$fronteggDomain\""
|
|
728
|
+
// buildConfigField "String", 'FRONTEGG_CLIENT_ID', "\"$fronteggClientId\""
|
|
729
|
+
}
|
|
730
|
+
```
|
|
731
|
+
|
|
732
|
+
**Secondly, Add AssetLinks for Each Region:**
|
|
733
|
+
|
|
734
|
+
For each region, configuring your Android `AssetLinks`. This is vital for proper API routing and authentication.
|
|
735
|
+
Follow [Config Android AssetLinks](#config-android-assetlinks) to add your Android domains to your Frontegg application.
|
|
736
|
+
|
|
737
|
+
**Lastly, Add Intent-Filter in Manifest.xml:**
|
|
738
|
+
|
|
739
|
+
The first domain will be placed automatically in the `AndroidManifest.xml` file. For each additional region, you will
|
|
740
|
+
need to add an `intent-filter`.
|
|
741
|
+
|
|
742
|
+
NOTE: if you are using `Custom Chrome Tab` you have to use `android:name` `com.frontegg.android.HostedAuthActivity` instead of `com.frontegg.android.EmbeddedAuthActivity`
|
|
743
|
+
|
|
744
|
+
```xml
|
|
745
|
+
|
|
746
|
+
<application>
|
|
747
|
+
<activity android:exported="true" android:name="com.frontegg.android.EmbeddedAuthActivity"
|
|
748
|
+
tools:node="merge">
|
|
749
|
+
<intent-filter android:autoVerify="true">
|
|
750
|
+
<action android:name="android.intent.action.VIEW" />
|
|
751
|
+
|
|
752
|
+
<category android:name="android.intent.category.DEFAULT" />
|
|
753
|
+
<category android:name="android.intent.category.BROWSABLE" />
|
|
754
|
+
|
|
755
|
+
<data android:scheme="https" />
|
|
756
|
+
<!-- Modify second domain -->
|
|
757
|
+
<data android:host="{{FRONTEGG_DOMAIN_2}}" />
|
|
758
|
+
<data android:pathPrefix="/oauth/account/activate" />
|
|
759
|
+
<data android:pathPrefix="/oauth/account/invitation/accept" />
|
|
760
|
+
<data android:pathPrefix="/oauth/account/reset-password" />
|
|
761
|
+
<data android:pathPrefix="/oauth/account/social/success" />
|
|
762
|
+
<data android:pathPrefix="/oauth/account/login/magic-link" />
|
|
763
|
+
</intent-filter>
|
|
764
|
+
</activity>
|
|
765
|
+
|
|
766
|
+
<activity android:exported="true" android:name="com.frontegg.android.AuthenticationActivity"
|
|
767
|
+
tools:node="merge">
|
|
768
|
+
<intent-filter>
|
|
769
|
+
<action android:name="android.intent.action.VIEW" />
|
|
770
|
+
|
|
771
|
+
<category android:name="android.intent.category.DEFAULT" />
|
|
772
|
+
<category android:name="android.intent.category.BROWSABLE" />
|
|
773
|
+
|
|
774
|
+
<!-- Modify second domain -->
|
|
775
|
+
<data android:host="{{FRONTEGG_DOMAIN_2}}" android:scheme="${package_name}" />
|
|
776
|
+
</intent-filter>
|
|
777
|
+
</activity>
|
|
778
|
+
</application>
|
|
779
|
+
```
|
package/android/build.gradle
CHANGED
|
@@ -21,7 +21,7 @@ android {
|
|
|
21
21
|
namespace "com.frontegg.ionic"
|
|
22
22
|
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 33
|
|
23
23
|
defaultConfig {
|
|
24
|
-
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion :
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 26
|
|
25
25
|
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 33
|
|
26
26
|
versionCode 1
|
|
27
27
|
versionName "1.0"
|
|
@@ -55,7 +55,7 @@ dependencies {
|
|
|
55
55
|
implementation "androidx.browser:browser:1.5.0"
|
|
56
56
|
implementation 'io.reactivex.rxjava3:rxkotlin:3.0.1'
|
|
57
57
|
implementation 'com.google.code.gson:gson:2.8.9'
|
|
58
|
-
implementation 'com.frontegg.sdk:android:1.
|
|
58
|
+
implementation 'com.frontegg.sdk:android:1.2.2'
|
|
59
59
|
|
|
60
60
|
testImplementation "junit:junit:$junitVersion"
|
|
61
61
|
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
@@ -7,14 +7,21 @@ import android.os.Looper;
|
|
|
7
7
|
import com.frontegg.android.FronteggApp;
|
|
8
8
|
import com.frontegg.android.FronteggAuth;
|
|
9
9
|
import com.frontegg.android.models.User;
|
|
10
|
+
import com.frontegg.android.regions.RegionConfig;
|
|
10
11
|
import com.getcapacitor.JSObject;
|
|
11
12
|
import com.getcapacitor.Plugin;
|
|
12
13
|
import com.getcapacitor.PluginCall;
|
|
14
|
+
import com.getcapacitor.PluginConfig;
|
|
13
15
|
import com.getcapacitor.PluginMethod;
|
|
14
16
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
15
17
|
|
|
16
|
-
import
|
|
18
|
+
import org.json.JSONArray;
|
|
19
|
+
import org.json.JSONException;
|
|
20
|
+
import org.json.JSONObject;
|
|
21
|
+
|
|
22
|
+
import java.util.ArrayList;
|
|
17
23
|
import java.util.HashMap;
|
|
24
|
+
import java.util.List;
|
|
18
25
|
import java.util.Map;
|
|
19
26
|
import java.util.Objects;
|
|
20
27
|
import java.util.concurrent.ExecutorService;
|
|
@@ -26,18 +33,52 @@ import io.reactivex.rxjava3.disposables.Disposable;
|
|
|
26
33
|
@CapacitorPlugin(name = "FronteggNative")
|
|
27
34
|
public class FronteggNativePlugin extends Plugin {
|
|
28
35
|
private Disposable disposable = null;
|
|
29
|
-
private Debouncer debouncer = new Debouncer(50); // 200ms delay
|
|
36
|
+
private final Debouncer debouncer = new Debouncer(50); // 200ms delay
|
|
30
37
|
|
|
31
38
|
@Override
|
|
32
39
|
public void load() {
|
|
33
|
-
Map<String, String> constants = this.getConstants();
|
|
34
40
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
// for regions initialization
|
|
42
|
+
List<RegionConfig> regions = new ArrayList<>();
|
|
43
|
+
JSONArray array;
|
|
44
|
+
try {
|
|
45
|
+
array = this.getConfig().getConfigJSON().optJSONArray("regions");
|
|
46
|
+
|
|
47
|
+
if (array == null) {
|
|
48
|
+
array = new JSONArray();
|
|
49
|
+
}
|
|
50
|
+
for (int i = 0; i < array.length(); i++) {
|
|
51
|
+
JSONObject regionJson = (JSONObject) array.get(i);
|
|
52
|
+
regions.add(new RegionConfig(
|
|
53
|
+
regionJson.getString("key"),
|
|
54
|
+
regionJson.getString("baseUrl"),
|
|
55
|
+
regionJson.getString("clientId")
|
|
56
|
+
));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
} catch (JSONException e) {
|
|
60
|
+
throw new RuntimeException(e);
|
|
61
|
+
}
|
|
40
62
|
|
|
63
|
+
if(regions.size() == 0) {
|
|
64
|
+
PluginConfig config = this.getConfig();
|
|
65
|
+
String baseUrl = config.getString("baseUrl");
|
|
66
|
+
String clientId = config.getString("clientId");
|
|
67
|
+
|
|
68
|
+
if (baseUrl == null || clientId == null) {
|
|
69
|
+
throw new RuntimeException("Missing required config parameters: baseUrl, clientId");
|
|
70
|
+
}
|
|
71
|
+
if(baseUrl.startsWith("https://")) {
|
|
72
|
+
baseUrl = baseUrl.substring(baseUrl.indexOf("://") + 3);
|
|
73
|
+
}
|
|
74
|
+
FronteggApp.Companion.init(
|
|
75
|
+
baseUrl,
|
|
76
|
+
clientId,
|
|
77
|
+
this.getContext()
|
|
78
|
+
);
|
|
79
|
+
}else {
|
|
80
|
+
FronteggApp.Companion.initWithRegions(regions, this.getContext());
|
|
81
|
+
}
|
|
41
82
|
|
|
42
83
|
FronteggAuth auth = FronteggAuth.Companion.getInstance();
|
|
43
84
|
|
|
@@ -73,6 +114,7 @@ public class FronteggNativePlugin extends Plugin {
|
|
|
73
114
|
boolean isLoading = auth.isLoading().getValue();
|
|
74
115
|
boolean initializing = auth.getInitializing().getValue();
|
|
75
116
|
boolean showLoader = auth.getShowLoader().getValue();
|
|
117
|
+
RegionConfig selectedRegion = auth.getSelectedRegion();
|
|
76
118
|
|
|
77
119
|
JSObject data = new JSObject();
|
|
78
120
|
|
|
@@ -85,6 +127,7 @@ public class FronteggNativePlugin extends Plugin {
|
|
|
85
127
|
data.put("isLoading", isLoading);
|
|
86
128
|
data.put("initializing", initializing);
|
|
87
129
|
data.put("showLoader", showLoader);
|
|
130
|
+
data.put("selectedRegion", Parser.regionToJSONObject(selectedRegion));
|
|
88
131
|
|
|
89
132
|
return data;
|
|
90
133
|
}
|
|
@@ -117,6 +160,22 @@ public class FronteggNativePlugin extends Plugin {
|
|
|
117
160
|
});
|
|
118
161
|
}
|
|
119
162
|
|
|
163
|
+
|
|
164
|
+
@PluginMethod
|
|
165
|
+
public void initWithRegion(PluginCall call) {
|
|
166
|
+
String regionKey = call.getString("regionKey");
|
|
167
|
+
if (regionKey == null) {
|
|
168
|
+
call.reject("No regionKey provided");
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
ExecutorService executor = Executors.newSingleThreadExecutor();
|
|
172
|
+
executor.submit(() -> {
|
|
173
|
+
FronteggApp.Companion.getInstance().initWithRegion(regionKey);
|
|
174
|
+
Handler handler = new Handler(Looper.getMainLooper());
|
|
175
|
+
handler.post(call::resolve);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
|
|
120
179
|
@PluginMethod
|
|
121
180
|
public void refreshToken(PluginCall call) {
|
|
122
181
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
|
@@ -133,43 +192,23 @@ public class FronteggNativePlugin extends Plugin {
|
|
|
133
192
|
}
|
|
134
193
|
|
|
135
194
|
|
|
136
|
-
|
|
195
|
+
@PluginMethod
|
|
196
|
+
public void getConstants(PluginCall call) {
|
|
197
|
+
|
|
198
|
+
String baseUrl = FronteggAuth.Companion.getInstance().getBaseUrl();
|
|
199
|
+
String clientId = FronteggAuth.Companion.getInstance().getBaseUrl();
|
|
137
200
|
String packageName = getContext().getPackageName();
|
|
138
|
-
String className = packageName + ".BuildConfig";
|
|
139
201
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
resultMap.put("baseUrl", baseUrl);
|
|
151
|
-
resultMap.put("clientId", clientId);
|
|
152
|
-
resultMap.put("bundleId", packageName);
|
|
153
|
-
|
|
154
|
-
return resultMap;
|
|
155
|
-
} catch (ClassNotFoundException e) {
|
|
156
|
-
System.out.println("Class not found: " + className);
|
|
157
|
-
throw new RuntimeException(e);
|
|
158
|
-
} catch (NoSuchFieldException e) {
|
|
159
|
-
System.out.println(
|
|
160
|
-
"Field not found in BuildConfig: " +
|
|
161
|
-
"buildConfigField \"String\", 'FRONTEGG_DOMAIN', \"\\\"$fronteggDomain\\\"\"\n" +
|
|
162
|
-
"buildConfigField \"String\", 'FRONTEGG_CLIENT_ID', \"\\\"$fronteggClientId\\\"\""
|
|
163
|
-
);
|
|
164
|
-
throw new RuntimeException(e);
|
|
165
|
-
} catch (IllegalAccessException e) {
|
|
166
|
-
System.out.println(
|
|
167
|
-
"Access problem with field in BuildConfig: " +
|
|
168
|
-
"buildConfigField \"String\", 'FRONTEGG_DOMAIN', \"\\\"$fronteggDomain\\\"\"\n" +
|
|
169
|
-
"buildConfigField \"String\", 'FRONTEGG_CLIENT_ID', \"\\\"$fronteggClientId\\\"\""
|
|
170
|
-
);
|
|
171
|
-
throw new RuntimeException(e);
|
|
172
|
-
}
|
|
202
|
+
List<RegionConfig> regionsData = FronteggApp.Companion.getInstance().getRegions();
|
|
203
|
+
|
|
204
|
+
JSObject resultMap = new JSObject();
|
|
205
|
+
resultMap.put("baseUrl", baseUrl);
|
|
206
|
+
resultMap.put("clientId", clientId);
|
|
207
|
+
resultMap.put("bundleId", packageName);
|
|
208
|
+
resultMap.put("isRegional", regionsData.size() > 0);
|
|
209
|
+
resultMap.put("regionData", Parser.regionsToJSONObject(regionsData));
|
|
210
|
+
|
|
211
|
+
call.resolve(resultMap);
|
|
173
212
|
}
|
|
174
213
|
|
|
175
214
|
}
|
|
@@ -2,11 +2,16 @@ package com.frontegg.ionic;
|
|
|
2
2
|
|
|
3
3
|
import com.frontegg.android.models.User;
|
|
4
4
|
|
|
5
|
+
import org.json.JSONArray;
|
|
5
6
|
import org.json.JSONException;
|
|
6
7
|
import org.json.JSONObject;
|
|
7
8
|
|
|
9
|
+
import com.frontegg.android.regions.RegionConfig;
|
|
8
10
|
import com.google.gson.Gson;
|
|
9
11
|
|
|
12
|
+
import java.util.List;
|
|
13
|
+
import java.util.Map;
|
|
14
|
+
|
|
10
15
|
public class Parser {
|
|
11
16
|
|
|
12
17
|
|
|
@@ -19,4 +24,25 @@ public class Parser {
|
|
|
19
24
|
}
|
|
20
25
|
}
|
|
21
26
|
|
|
27
|
+
|
|
28
|
+
public static JSONObject regionToJSONObject(RegionConfig regionConfig) {
|
|
29
|
+
String jsonStr = new Gson().toJson(regionConfig, RegionConfig.class);
|
|
30
|
+
try {
|
|
31
|
+
return new JSONObject(jsonStr);
|
|
32
|
+
} catch (JSONException e) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
public static JSONArray regionsToJSONObject(List<RegionConfig> regions) {
|
|
37
|
+
|
|
38
|
+
JSONArray regionsData = new JSONArray();
|
|
39
|
+
for (RegionConfig regionConfig : regions) {
|
|
40
|
+
JSONObject region = regionToJSONObject(regionConfig);
|
|
41
|
+
if(region != null) {
|
|
42
|
+
regionsData.put(region);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return regionsData;
|
|
46
|
+
}
|
|
47
|
+
|
|
22
48
|
}
|
|
@@ -10,19 +10,71 @@ export interface FronteggState {
|
|
|
10
10
|
isAuthenticated: boolean;
|
|
11
11
|
user: User | null;
|
|
12
12
|
showLoader: boolean;
|
|
13
|
+
selectedRegion: string | null;
|
|
13
14
|
}
|
|
14
15
|
export declare type SubscribeFunc<T, K extends keyof T> = (value: T[K]) => void;
|
|
15
16
|
export declare type SubscribeMap<T> = {
|
|
16
17
|
[K in keyof T]: Set<SubscribeFunc<T, K>>;
|
|
17
18
|
};
|
|
19
|
+
export interface FronteggConstants {
|
|
20
|
+
baseUrl: string;
|
|
21
|
+
clientId: string;
|
|
22
|
+
bundleId: string;
|
|
23
|
+
isRegional: boolean;
|
|
24
|
+
regionData?: {
|
|
25
|
+
key: string;
|
|
26
|
+
baseUrl: string;
|
|
27
|
+
clientId: string;
|
|
28
|
+
}[];
|
|
29
|
+
}
|
|
18
30
|
export interface FronteggNativePlugin {
|
|
19
31
|
addListener(eventName: string, listenerFunc: ListenerCallback): Promise<PluginListenerHandle> & PluginListenerHandle;
|
|
20
|
-
getConstants(): Promise<
|
|
32
|
+
getConstants(): Promise<FronteggConstants>;
|
|
21
33
|
getAuthState(): Promise<FronteggState>;
|
|
22
34
|
login(): Promise<void>;
|
|
23
35
|
logout(): void;
|
|
24
36
|
switchTenant(payload: {
|
|
25
37
|
tenantId: string;
|
|
26
38
|
}): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* used to initialize the plugin with multiple regions
|
|
41
|
+
* for more information see:
|
|
42
|
+
* iOS: https://github.com/frontegg/frontegg-ios-swift#multi-region-support
|
|
43
|
+
* Android: https://github.com/frontegg/frontegg-android-kotlin#multi-region-support
|
|
44
|
+
*/
|
|
45
|
+
initWithRegion(payload: {
|
|
46
|
+
regionKey: string;
|
|
47
|
+
}): Promise<void>;
|
|
27
48
|
refreshToken(): Promise<void>;
|
|
28
49
|
}
|
|
50
|
+
export declare type RegionConfig = {
|
|
51
|
+
key: string;
|
|
52
|
+
baseUrl: string;
|
|
53
|
+
clientId: string;
|
|
54
|
+
};
|
|
55
|
+
declare type FronteggNativeStandardOptions = {
|
|
56
|
+
baseUrl: string;
|
|
57
|
+
clientId: string;
|
|
58
|
+
};
|
|
59
|
+
declare type FronteggNativeRegionOptions = {
|
|
60
|
+
/**
|
|
61
|
+
* This is an array of regions to be used as frontegg app.
|
|
62
|
+
*
|
|
63
|
+
* @since 1.0.0
|
|
64
|
+
* @example [{key: "us", baseUrl: "https://us-api.frontegg.com", clientId: "us-client-id"}]
|
|
65
|
+
*/
|
|
66
|
+
regions: RegionConfig[];
|
|
67
|
+
};
|
|
68
|
+
declare type FronteggNativeOptions = (FronteggNativeStandardOptions | FronteggNativeRegionOptions) & {
|
|
69
|
+
handleLoginWithSocialLogin?: boolean;
|
|
70
|
+
handleLoginWithSSO?: boolean;
|
|
71
|
+
};
|
|
72
|
+
declare module "@capacitor/cli" {
|
|
73
|
+
interface PluginsConfig {
|
|
74
|
+
/**
|
|
75
|
+
* You can configure the way the push notifications are displayed when the app is in foreground.
|
|
76
|
+
*/
|
|
77
|
+
FronteggNative?: FronteggNativeOptions;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["\nimport type { ListenerCallback, PluginListenerHandle } from '@capacitor/core';\nimport type { ITenantsResponse, IUserProfile } from '@frontegg/rest-api';\n\nexport type User = IUserProfile & {\n tenants: ITenantsResponse[];\n activeTenant: ITenantsResponse\n}\n\nexport interface FronteggState {\n accessToken: string | null;\n refreshToken: string | null;\n isAuthenticated: boolean;\n user: User | null;\n showLoader: boolean;\n selectedRegion: string | null;\n}\n\n\nexport type SubscribeFunc<T, K extends keyof T> = (value: T[K]) => void\nexport type SubscribeMap<T> = {\n [K in keyof T]: Set<SubscribeFunc<T, K>>\n}\n\n\nexport interface FronteggConstants {\n baseUrl: string;\n clientId: string;\n bundleId: string;\n isRegional: boolean;\n regionData?: { key: string, baseUrl: string, clientId: string }[]\n}\n\nexport interface FronteggNativePlugin {\n addListener(eventName: string, listenerFunc: ListenerCallback): Promise<PluginListenerHandle> & PluginListenerHandle\n\n getConstants(): Promise<FronteggConstants>;\n\n getAuthState(): Promise<FronteggState>;\n\n login(): Promise<void>;\n\n logout(): void;\n\n switchTenant(payload: { tenantId: string }): Promise<void>;\n\n /**\n * used to initialize the plugin with multiple regions\n * for more information see:\n * iOS: https://github.com/frontegg/frontegg-ios-swift#multi-region-support\n * Android: https://github.com/frontegg/frontegg-android-kotlin#multi-region-support\n */\n initWithRegion(payload: { regionKey: string }): Promise<void>;\n\n refreshToken(): Promise<void>;\n\n}\n\n\n\nexport type RegionConfig = {\n key: string;\n baseUrl: string;\n clientId: string;\n};\n\n\n\ntype FronteggNativeStandardOptions = {\n baseUrl: string;\n clientId: string;\n\n}\ntype FronteggNativeRegionOptions = {\n /**\n * This is an array of regions to be used as frontegg app.\n *\n * @since 1.0.0\n * @example [{key: \"us\", baseUrl: \"https://us-api.frontegg.com\", clientId: \"us-client-id\"}]\n */\n regions: RegionConfig[];\n}\ntype FronteggNativeOptions = (FronteggNativeStandardOptions | FronteggNativeRegionOptions) & {\n handleLoginWithSocialLogin?: boolean;\n handleLoginWithSSO?: boolean;\n}\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\ndeclare module \"@capacitor/cli\" {\n export interface PluginsConfig {\n /**\n * You can configure the way the push notifications are displayed when the app is in foreground.\n */\n FronteggNative?: FronteggNativeOptions;\n }\n}\n"]}
|