createAuthenticationRequestUrl function

Uri createAuthenticationRequestUrl(
  1. CreateUrlOptions options
)

Create a URL that can be used to redirect the browser to request authentication (e.g. using the authentication provider). Will throw if some options are invalid.

Implementation

Uri createAuthenticationRequestUrl(CreateUrlOptions options) {
  final url = Uri.parse(
    options.identityProvider?.toString() ??
        '$identityProviderDefault/authorize',
  );
  url.queryParameters.addEntries([
    const MapEntry('response_type', 'token'),
    MapEntry('login_hint', options.publicKey.toDer().toHex()),
    MapEntry('redirect_uri', options.redirectUri?.toString() ?? ''),
    MapEntry(
      'scope',
      options.scope
          .map((p) => p is String ? Principal.fromText(p) : p)
          .map((p) => p.toString())
          .join(' '),
    ),
    const MapEntry('state', ''),
  ]);

  return url;
}