authorizeInteractive static method

Future<AuthorizationResponse?> authorizeInteractive({
  1. required BuildContext context,
  2. required String title,
  3. required InteractiveAuthorizationRequest request,
})

Implementation

static Future<AuthorizationResponse?> authorizeInteractive({
  required BuildContext context,
  required String title,
  required InteractiveAuthorizationRequest request,
}) async {
  late String? responseUrl;

  final authEndpoint = Uri.parse(request.configuration.authorizationEndpoint);
  final uri = authEndpoint.replace(
    queryParameters: <String, String>{
      ...authEndpoint.queryParameters,
      ...request.toMap(),
    },
  );

  //These are special cases for the various different platforms because of limitations in pubspec.yaml
  if (!kIsWeb && (Platform.isIOS || Platform.isAndroid)) {
    responseUrl = await OpenIdConnectAndroidiOS.authorizeInteractive(
      context: context,
      title: title,
      authorizationUrl: uri.toString(),
      redirectUrl: request.redirectUrl,
      popupHeight: request.popupHeight,
      popupWidth: request.popupWidth,
    );
  } else if (kIsWeb) {
    final storage = FlutterSecureStorage();
    await storage.write(
        key: CODE_VERIFIER_STORAGE_KEY, value: request.codeVerifier);
    await storage.write(
        key: CODE_CHALLENGE_STORAGE_KEY, value: request.codeChallenge);

    responseUrl = await _platform.authorizeInteractive(
      context: context,
      title: title,
      authorizationUrl: uri.toString(),
      redirectUrl: request.redirectUrl,
      popupHeight: request.popupHeight,
      popupWidth: request.popupWidth,
      useWebRedirectLoop: !request.useWebPopup,
    );

    if (responseUrl == null) return null;

    await storage.delete(key: CODE_VERIFIER_STORAGE_KEY);
    await storage.delete(key: CODE_CHALLENGE_STORAGE_KEY);
  } else {
    //TODO add other implementations as they become available. For now, all desktop uses device code flow instead of authorization code flow
    return await OpenIdConnect.authorizeDevice(
      request: DeviceAuthorizationRequest(
        audience: null,
        clientId: request.clientId,
        clientSecret: request.clientSecret,
        configuration: request.configuration,
        scopes: request.scopes,
        additionalParameters: request.additionalParameters,
      ),
    );
  }

  return await _completeCodeExchange(request: request, url: responseUrl);
}