generateSignInUri function
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);
}