generateSignInUri function

Uri generateSignInUri({
  1. required String authorizationEndpoint,
  2. required dynamic clientId,
  3. required String redirectUri,
  4. required String codeChallenge,
  5. required String state,
  6. List<String>? scopes,
  7. List<String>? resources,
  8. InteractionMode? interactionMode,
  9. String prompt = _prompt,
})

Generate the sign-in URI (Authorization URI). This URI will be used to initiate the OIDC authentication flow.

Implementation

Uri generateSignInUri(
    {required String authorizationEndpoint,
    required clientId,
    required String redirectUri,
    required String codeChallenge,
    required String state,
    List<String>? scopes,
    List<String>? resources,
    InteractionMode? interactionMode,
    String prompt = _prompt}) {
  var signInUri = Uri.parse(authorizationEndpoint);

  Map<String, dynamic> queryParameters = {
    'client_id': clientId,
    'redirect_uri': redirectUri,
    'code_challenge': codeChallenge,
    'code_challenge_method': _codeChallengeMethod,
    'state': state,
    'scope': withReservedScopes(scopes ?? []).join(' '),
    'response_type': _responseType,
    'prompt': prompt,
  };

  // Auto add organization resource if scopes contains organization scope
  if (scopes != null && scopes.contains(LogtoUserScope.organizations.value)) {
    resources ??= [];

    if (!resources.contains(LogtoReservedResource.organization.value)) {
      resources.add(LogtoReservedResource.organization.value);
    }
  }

  if (resources != null && resources.isNotEmpty) {
    queryParameters.addAll({'resource': resources});
  }

  if (interactionMode != null) {
    // need to align with the backend OIDC params name
    queryParameters.addAll({'interaction_mode': interactionMode.value});
  }

  return addQueryParameters(signInUri, queryParameters);
}