@frontegg/ionic-capacitor 1.0.0-alpha.3 → 2.0.0
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 +255 -31
- package/android/build.gradle +2 -2
- package/android/src/main/java/com/frontegg/ionic/FronteggNativePlugin.java +76 -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 +106 -25
- 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
|
|
|
@@ -356,6 +362,17 @@ import { FronteggService } from '@frontegg/ionic-capacitor';
|
|
|
356
362
|
this.fronteggService.$isAuthenticated.subscribe(async () => {
|
|
357
363
|
window.location.reload()
|
|
358
364
|
});
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Listens to application visibility changes
|
|
368
|
+
* Reload the page to trigger canActivate
|
|
369
|
+
* when application returns from login page without authentication
|
|
370
|
+
*/
|
|
371
|
+
document.addEventListener('visibilitychange', () => {
|
|
372
|
+
if (document.visibilityState === 'visible' && !this.fronteggService.getState().isAuthenticated) {
|
|
373
|
+
window.location.reload()
|
|
374
|
+
}
|
|
375
|
+
});
|
|
359
376
|
}
|
|
360
377
|
|
|
361
378
|
/**
|
|
@@ -418,7 +435,7 @@ import { FronteggService } from '@frontegg/ionic-capacitor';
|
|
|
418
435
|
2. Open the `src/app-routing.module.ts` file and add wrap the app routes with loadChildren and apply CanActivate guard:
|
|
419
436
|
|
|
420
437
|
```typescript
|
|
421
|
-
import { AuthGuard } from './auth.
|
|
438
|
+
import { AuthGuard } from './auth.guard';
|
|
422
439
|
|
|
423
440
|
const routes: Routes = [
|
|
424
441
|
{
|
|
@@ -505,8 +522,8 @@ Frontegg SDK supports two authentication methods:
|
|
|
505
522
|
|
|
506
523
|
- Embedded Webview
|
|
507
524
|
- Hosted Webview
|
|
508
|
-
|
|
509
|
-
|
|
525
|
+
- `iOS`: ASWebAuthenticationSession
|
|
526
|
+
- `Android`: Custom Chrome Tab
|
|
510
527
|
|
|
511
528
|
By default, Frontegg SDK will use Embedded Webview.
|
|
512
529
|
|
|
@@ -519,14 +536,11 @@ To use ASWebAuthenticationSession you have to set `embeddedMode` to `NO` in `Fro
|
|
|
519
536
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN">
|
|
520
537
|
<plist version="1.0">
|
|
521
538
|
<dict>
|
|
522
|
-
<key>
|
|
523
|
-
<
|
|
524
|
-
<key>clientId</key>
|
|
525
|
-
<string>[CLIENT_ID_FROM_PREVIOUS_STEP]</string>
|
|
526
|
-
|
|
539
|
+
<key>lateInit</key>
|
|
540
|
+
<true/>
|
|
527
541
|
<!-- START -->
|
|
528
542
|
<key>embeddedMode</key>
|
|
529
|
-
<
|
|
543
|
+
<false/>
|
|
530
544
|
<!-- END -->
|
|
531
545
|
</dict>
|
|
532
546
|
</plist>
|
|
@@ -553,3 +567,213 @@ the application manifest:
|
|
|
553
567
|
</application>
|
|
554
568
|
</manifest>
|
|
555
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,46 @@ 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().getJSONArray("regions");
|
|
46
|
+
|
|
47
|
+
for (int i = 0; i < array.length(); i++) {
|
|
48
|
+
JSONObject regionJson = (JSONObject) array.get(i);
|
|
49
|
+
regions.add(new RegionConfig(
|
|
50
|
+
regionJson.getString("key"),
|
|
51
|
+
regionJson.getString("baseUrl"),
|
|
52
|
+
regionJson.getString("clientId")
|
|
53
|
+
));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
} catch (JSONException e) {
|
|
57
|
+
throw new RuntimeException(e);
|
|
58
|
+
}
|
|
40
59
|
|
|
60
|
+
if(regions.size() == 0) {
|
|
61
|
+
PluginConfig config = this.getConfig();
|
|
62
|
+
String baseUrl = config.getString("baseUrl");
|
|
63
|
+
String clientId = config.getString("clientId");
|
|
64
|
+
String regionKey = config.getString("regionKey");
|
|
65
|
+
if (baseUrl == null || clientId == null || regionKey == null) {
|
|
66
|
+
throw new RuntimeException("Missing required config parameters: baseUrl, clientId, regionKey");
|
|
67
|
+
}
|
|
68
|
+
FronteggApp.Companion.init(
|
|
69
|
+
baseUrl,
|
|
70
|
+
clientId,
|
|
71
|
+
this.getContext()
|
|
72
|
+
);
|
|
73
|
+
}else {
|
|
74
|
+
FronteggApp.Companion.initWithRegions(regions, this.getContext());
|
|
75
|
+
}
|
|
41
76
|
|
|
42
77
|
FronteggAuth auth = FronteggAuth.Companion.getInstance();
|
|
43
78
|
|
|
@@ -73,6 +108,7 @@ public class FronteggNativePlugin extends Plugin {
|
|
|
73
108
|
boolean isLoading = auth.isLoading().getValue();
|
|
74
109
|
boolean initializing = auth.getInitializing().getValue();
|
|
75
110
|
boolean showLoader = auth.getShowLoader().getValue();
|
|
111
|
+
RegionConfig selectedRegion = auth.getSelectedRegion();
|
|
76
112
|
|
|
77
113
|
JSObject data = new JSObject();
|
|
78
114
|
|
|
@@ -85,6 +121,7 @@ public class FronteggNativePlugin extends Plugin {
|
|
|
85
121
|
data.put("isLoading", isLoading);
|
|
86
122
|
data.put("initializing", initializing);
|
|
87
123
|
data.put("showLoader", showLoader);
|
|
124
|
+
data.put("selectedRegion", Parser.regionToJSONObject(selectedRegion));
|
|
88
125
|
|
|
89
126
|
return data;
|
|
90
127
|
}
|
|
@@ -117,6 +154,22 @@ public class FronteggNativePlugin extends Plugin {
|
|
|
117
154
|
});
|
|
118
155
|
}
|
|
119
156
|
|
|
157
|
+
|
|
158
|
+
@PluginMethod
|
|
159
|
+
public void initWithRegion(PluginCall call) {
|
|
160
|
+
String regionKey = call.getString("regionKey");
|
|
161
|
+
if (regionKey == null) {
|
|
162
|
+
call.reject("No regionKey provided");
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
ExecutorService executor = Executors.newSingleThreadExecutor();
|
|
166
|
+
executor.submit(() -> {
|
|
167
|
+
FronteggApp.Companion.getInstance().initWithRegion(regionKey);
|
|
168
|
+
Handler handler = new Handler(Looper.getMainLooper());
|
|
169
|
+
handler.post(call::resolve);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
120
173
|
@PluginMethod
|
|
121
174
|
public void refreshToken(PluginCall call) {
|
|
122
175
|
ExecutorService executor = Executors.newSingleThreadExecutor();
|
|
@@ -133,43 +186,23 @@ public class FronteggNativePlugin extends Plugin {
|
|
|
133
186
|
}
|
|
134
187
|
|
|
135
188
|
|
|
136
|
-
|
|
189
|
+
@PluginMethod
|
|
190
|
+
public void getConstants(PluginCall call) {
|
|
191
|
+
|
|
192
|
+
String baseUrl = FronteggAuth.Companion.getInstance().getBaseUrl();
|
|
193
|
+
String clientId = FronteggAuth.Companion.getInstance().getBaseUrl();
|
|
137
194
|
String packageName = getContext().getPackageName();
|
|
138
|
-
String className = packageName + ".BuildConfig";
|
|
139
195
|
|
|
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
|
-
}
|
|
196
|
+
List<RegionConfig> regionsData = FronteggApp.Companion.getInstance().getRegions();
|
|
197
|
+
|
|
198
|
+
JSObject resultMap = new JSObject();
|
|
199
|
+
resultMap.put("baseUrl", baseUrl);
|
|
200
|
+
resultMap.put("clientId", clientId);
|
|
201
|
+
resultMap.put("bundleId", packageName);
|
|
202
|
+
resultMap.put("isRegional", regionsData.size() > 0);
|
|
203
|
+
resultMap.put("regionData", Parser.regionsToJSONObject(regionsData));
|
|
204
|
+
|
|
205
|
+
call.resolve(resultMap);
|
|
173
206
|
}
|
|
174
207
|
|
|
175
208
|
}
|
|
@@ -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"]}
|