|
2 | 2 |
|
3 | 3 |
|
4 | 4 |
|
| 5 | +import android.app.Activity; |
5 | 6 | import android.os.Handler; |
6 | 7 | import android.os.Looper; |
7 | 8 | import android.util.Log; |
8 | 9 |
|
9 | 10 | import kotlin.Unit; |
10 | 11 |
|
| 12 | +import com.frontegg.android.AdminPortalActivity; |
11 | 13 | import com.frontegg.android.FronteggApp; |
12 | 14 | import com.frontegg.android.FronteggAppKt; |
13 | 15 | import com.frontegg.android.FronteggAuth; |
| 16 | +import com.frontegg.android.models.Entitlement; |
14 | 17 | import com.frontegg.android.models.User; |
15 | 18 | import com.frontegg.android.regions.RegionConfig; |
16 | 19 | import com.getcapacitor.JSObject; |
@@ -295,6 +298,62 @@ public void refreshToken(PluginCall call) { |
295 | 298 | } |
296 | 299 |
|
297 | 300 |
|
| 301 | + @PluginMethod |
| 302 | + public void loadEntitlements(PluginCall call) { |
| 303 | + Boolean forceRefresh = call.getBoolean("forceRefresh", false); |
| 304 | + FronteggAppKt.getFronteggAuth(this.getContext()).loadEntitlements( |
| 305 | + forceRefresh != null ? forceRefresh : false, |
| 306 | + (success) -> { |
| 307 | + JSObject result = new JSObject(); |
| 308 | + result.put("success", success); |
| 309 | + call.resolve(result); |
| 310 | + return null; |
| 311 | + }); |
| 312 | + } |
| 313 | + |
| 314 | + @PluginMethod |
| 315 | + public void getFeatureEntitlement(PluginCall call) { |
| 316 | + String key = call.getString("key"); |
| 317 | + if (key == null) { |
| 318 | + call.reject("No key provided"); |
| 319 | + return; |
| 320 | + } |
| 321 | + Entitlement entitlement = FronteggAppKt.getFronteggAuth(this.getContext()) |
| 322 | + .getFeatureEntitlements(key, null); |
| 323 | + JSObject result = new JSObject(); |
| 324 | + result.put("isEntitled", entitlement.isEntitled()); |
| 325 | + result.put("justification", entitlement.getJustification()); |
| 326 | + call.resolve(result); |
| 327 | + } |
| 328 | + |
| 329 | + @PluginMethod |
| 330 | + public void getPermissionEntitlement(PluginCall call) { |
| 331 | + String key = call.getString("key"); |
| 332 | + if (key == null) { |
| 333 | + call.reject("No key provided"); |
| 334 | + return; |
| 335 | + } |
| 336 | + Entitlement entitlement = FronteggAppKt.getFronteggAuth(this.getContext()) |
| 337 | + .getPermissionEntitlements(key, null); |
| 338 | + JSObject result = new JSObject(); |
| 339 | + result.put("isEntitled", entitlement.isEntitled()); |
| 340 | + result.put("justification", entitlement.getJustification()); |
| 341 | + call.resolve(result); |
| 342 | + } |
| 343 | + |
| 344 | + @PluginMethod |
| 345 | + public void showAdminPortal(PluginCall call) { |
| 346 | + Activity activity = this.getActivity(); |
| 347 | + if (activity == null) { |
| 348 | + call.reject("No host activity available"); |
| 349 | + return; |
| 350 | + } |
| 351 | + new Handler(Looper.getMainLooper()).post(() -> { |
| 352 | + AdminPortalActivity.open(activity); |
| 353 | + call.resolve(); |
| 354 | + }); |
| 355 | + } |
| 356 | + |
298 | 357 | @PluginMethod |
299 | 358 | public void getAuthState(PluginCall call) { |
300 | 359 | call.resolve(getData()); |
|
0 commit comments