loginWithPassword method

Future<OpenIdIdentity> loginWithPassword({
  1. required String userName,
  2. required String password,
  3. Iterable<String>? prompts,
  4. Map<String, String>? additionalParameters,
})

Implementation

Future<OpenIdIdentity> loginWithPassword(
    {required String userName,
    required String password,
    Iterable<String>? prompts,
    Map<String, String>? additionalParameters}) async {
  if (_autoRenewTimer != null) _autoRenewTimer = null;

  try {
    //Make sure we have the discovery information
    await _verifyDiscoveryDocument();

    final request = PasswordAuthorizationRequest(
      configuration: configuration!,
      password: password,
      scopes: _getScopes(scopes),
      clientId: clientId,
      userName: userName,
      clientSecret: clientSecret,
      prompts: prompts,
      additionalParameters: additionalParameters,
      autoRefresh: autoRefresh,
    );

    final response = await OpenIdConnect.authorizePassword(request: request);

    //Load the idToken here
    await _completeLogin(response);

    if (autoRefresh) _setupAutoRenew();

    _raiseEvent(AuthEvent(AuthEventTypes.Success));

    return _identity!;
  } on Exception catch (e) {
    if (this._identity != null) {
      await OpenIdIdentity.clear();
      this._identity = null;
    }
    _raiseEvent(AuthEvent(AuthEventTypes.Error, message: e.toString()));
    throw AuthenticationException(e.toString());
  }
}