authorize method

  1. @override
Future<void> authorize(
  1. {String? tokenResponseString}
)
override

Initiates the authorization process using a WebView window.

Throws an error if WebView runtime is not available on the current device.

The authorization process involves discovering the OpenID Connect issuer, creating a client, launching a WebView window, and obtaining credentials.

Implementation

@override
Future<void> authorize({
  String? tokenResponseString,
}) async {
  bool isWebviewAvailable = await WebviewWindow.isWebviewAvailable();
  if (isWebviewAvailable == false) {
    throw 'WebView runtime is available on the current devices';
  }

  final issuer = await Issuer.discover(Uri.parse('$_issuerUrl/v2.0'));
  final client = Client(issuer, _clientId);

  urlLauncher(String urlString) async {
    var url = '$urlString$_query';
    _webview = await WebviewWindow.create(
      configuration: CreateConfiguration(
        windowHeight: 500,
        windowWidth: 500,
        title: "Authentication",
        userDataFolderWindows: await getWebViewPath(),
      ),
    );
    _webview?.launch(url);
    return _webview;
  }

  Authenticator authenticator = Authenticator(
    client,
    scopes: _scopes,
    port: _port,
    urlLancher: urlLauncher,
  );

  credential = await authenticator.authorize();
}