mirror of
https://github.com/hanskokx/arcane_implementations.git
synced 2026-05-14 02:19:05 +02:00
Update Entra interface
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -5,8 +5,7 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
class MicrosoftEntraInterface implements ArcaneAuthInterface {
|
class MicrosoftEntraInterface implements ArcaneAuthInterface {
|
||||||
MicrosoftEntraInterface._internal();
|
MicrosoftEntraInterface._internal();
|
||||||
static final ArcaneAuthInterface _instance =
|
static final ArcaneAuthInterface _instance = MicrosoftEntraInterface._internal();
|
||||||
MicrosoftEntraInterface._internal();
|
|
||||||
static ArcaneAuthInterface get I => _instance;
|
static ArcaneAuthInterface get I => _instance;
|
||||||
|
|
||||||
static bool _mocked = false;
|
static bool _mocked = false;
|
||||||
@@ -28,16 +27,13 @@ class MicrosoftEntraInterface implements ArcaneAuthInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<String?> get accessToken async =>
|
Future<String?> get accessToken async => _oauth?.getAccessToken() ?? Future.value(null);
|
||||||
_oauth?.getAccessToken() ?? Future.value(null);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> get isSignedIn async =>
|
Future<bool> get isSignedIn async => _oauth?.hasCachedAccountInformation ?? Future.value(false);
|
||||||
_oauth?.hasCachedAccountInformation ?? Future.value(false);
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> init() async {
|
Future<void> init() async {
|
||||||
if (_mocked) return;
|
|
||||||
if (_oauth != null) return;
|
if (_oauth != null) return;
|
||||||
|
|
||||||
final String? tenant = AppEnv.valueOf(EnvVar.adSsoTenant);
|
final String? tenant = AppEnv.valueOf(EnvVar.adSsoTenant);
|
||||||
@@ -46,28 +42,24 @@ class MicrosoftEntraInterface implements ArcaneAuthInterface {
|
|||||||
final String? redirectUri = AppEnv.valueOf(EnvVar.adSsoRedirectUri);
|
final String? redirectUri = AppEnv.valueOf(EnvVar.adSsoRedirectUri);
|
||||||
|
|
||||||
if (tenant == null) throw const FormatException('Tenant must not be null.');
|
if (tenant == null) throw const FormatException('Tenant must not be null.');
|
||||||
if (clientId == null)
|
if (clientId == null) throw const FormatException('Client ID must not be null.');
|
||||||
throw const FormatException('Client ID must not be null.');
|
|
||||||
if (scope == null) throw const FormatException('Scope must not be null.');
|
if (scope == null) throw const FormatException('Scope must not be null.');
|
||||||
if (redirectUri == null)
|
if (redirectUri == null) throw const FormatException('Redirect URI must not be null.');
|
||||||
throw const FormatException('Redirect URI must not be null.');
|
|
||||||
|
|
||||||
final Config config = Config(
|
final Config config = Config(
|
||||||
tenant: tenant,
|
tenant: tenant,
|
||||||
clientId: clientId,
|
clientId: clientId,
|
||||||
scope: scope,
|
scope: scope,
|
||||||
redirectUri: redirectUri,
|
redirectUri: redirectUri,
|
||||||
navigatorKey:
|
// Should be a GlobalKey<NavigatorState>() in the app's router
|
||||||
navigatorKey, // Should be a GlobalKey<NavigatorState>() in the app's router
|
navigatorKey: navigatorKey,
|
||||||
);
|
);
|
||||||
|
|
||||||
_oauth = AadOAuth(config);
|
_oauth = AadOAuth(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Result<void, String>> login<T>(
|
Future<Result<void, String>> login<T>({T? input, Future<void> Function()? onLoggedIn}) async {
|
||||||
{T? input, Future<void> Function()? onLoggedIn}) async {
|
|
||||||
if (_mocked) return Result.ok(null);
|
|
||||||
if (_oauth == null) await init();
|
if (_oauth == null) await init();
|
||||||
|
|
||||||
if (await isSignedIn) return Result.ok(null);
|
if (await isSignedIn) return Result.ok(null);
|
||||||
@@ -88,7 +80,6 @@ class MicrosoftEntraInterface implements ArcaneAuthInterface {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Result<void, String>> logout() async {
|
Future<Result<void, String>> logout() async {
|
||||||
if (_mocked) return Result.ok(null);
|
|
||||||
if (_oauth == null) await init();
|
if (_oauth == null) await init();
|
||||||
|
|
||||||
if (!await isSignedIn) return Result.error('Not signed in');
|
if (!await isSignedIn) return Result.error('Not signed in');
|
||||||
@@ -97,9 +88,4 @@ class MicrosoftEntraInterface implements ArcaneAuthInterface {
|
|||||||
|
|
||||||
return Result.ok(null);
|
return Result.ok(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@visibleForTesting
|
|
||||||
static void setMocked() {
|
|
||||||
_mocked = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user