initialize static method

Future<void> initialize({
  1. required String namespace,
  2. required String apiUrl,
  3. TransportCredentials? credentials,
  4. bool? debug,
  5. String? redirectUrl,
  6. List<OidcProviderType>? excludeOidcProviders,
  7. List<LoginType>? excludeAuthMechanisms,
})

Implementation

static Future<void> initialize({
  required String namespace,
  required String apiUrl,
  TransportCredentials? credentials,
  bool? debug,
  String? redirectUrl,
  List<OidcProviderType>? excludeOidcProviders,
  List<LoginType>? excludeAuthMechanisms,
}) async {
  setPathUrlStrategy();
  _apiUrl = apiUrl;
  _namespace = namespace;

  _redirectUrl = redirectUrl ?? (kIsWeb ? "${Uri.base}/callback" : "");
  _transportCredentials =
      credentials ?? CloudCredentials(apiUrl: Uri.parse(_apiUrl));
  _heraClient =
      await HeraChannel.publicServiceClient(_apiUrl, _transportCredentials);
  // get public key used to validate tokens client side
  HeraRequest publicKeysReq = HeraRequest(namespace: _namespace);
  HeraResponse heraResp = await _heraClient.getPublicKey(publicKeysReq);
  _heraPublicKey = heraResp.publicKey;
  // get config
  config = await initializeAuth();
  // init oidc providers
  config.oidcProviders.removeWhere((key, value) =>
      !value.enabled ||
      excludeOidcProviders?.contains(value.type) == true ||
      excludeAuthMechanisms?.contains(LoginType.OIDC_LOGIN) == true);
  // init login methods
  config.supportedLoginMechanisms.removeWhere(
      (element) => excludeAuthMechanisms?.contains(element) == true);
}