aad_b2c_webview icon indicating copy to clipboard operation
aad_b2c_webview copied to clipboard

Can't get token on iOS

Open uendellima opened this issue 8 months ago • 1 comments

Is there any configuration to be done on iOS to work? on Android i can get the token, but on iOS it stucks on a infinite loading using b2c_with_button widget and no function is called, neither onSuccess nor onFailure.

Actually, my redirect url is: <appId>://callback

uendellima avatar Apr 28 '25 16:04 uendellima

Hi @unleed

There is an improvement to the button login flow in aad_b2c_webview version: ^0.1.1

Below is a usage example that may help in testing. I look forward to your feedback to know if it worked correctly!

https://github.com/user-attachments/assets/e03f76f2-acf5-4118-b743-9bf34840b21d

Code

import 'package:aad_b2c_webview/aad_b2c_webview.dart';
import 'package:flutter/material.dart';

const aadB2CClientID = "<app-id>";
const aadB2CRedirectURL = "https://jwt.ms";
const aadB2CUserFlowName = "B2C_1_APPNAME_Signin";
const aadB2CScopes = ['openid', 'offline_access'];
const aadB2TenantName = "<tenantName>";
const aadB2CUserAuthFlow =
    "https://$aadB2TenantName.b2clogin.com/$aadB2TenantName.onmicrosoft.com";

class B2CWithButton extends StatelessWidget {
  B2CWithButton({super.key});

  final B2CWebViewParams params = B2CWebViewParams(
    responseType: Constants.defaultResponseType,
    tenantBaseUrl: aadB2CUserAuthFlow,
    clientId: aadB2CClientID,
    userFlowName: aadB2CUserFlowName,
    redirectUrl: aadB2CRedirectURL,
    scopes: aadB2CScopes,
    containsChallenge: true,
    isLoginFlow: true,
    loadingReplacement: const Scaffold(
      body: Center(
        child: CircularProgressIndicator(),
      ),
    ),
  );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: SafeArea(
        child: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              const Text(
                'Azure B2C Button',
                style: TextStyle(
                  fontSize: 24.0,
                  fontWeight: FontWeight.bold,
                ),
              ),
              const SizedBox(height: 16.0),
              AADB2CBase.button(
                params: params,
                settings: ButtonSettingsEntity(
                  onError: _onError,
                  onSuccess: _onSuccess,
                  onKeepLoading: _onKeepLoading,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  _onSuccess(
      BuildContext context,
      accessToken,
      idToken,
      refreshToken,
      ) {
    Navigator.of(context).push(
      MaterialPageRoute(
        builder: (_) => Scaffold(
          body: SafeArea(
            child: SingleChildScrollView(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  const Text(
                    'Success Flutter Page!',
                    style: TextStyle(
                      fontSize: 34.0,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  const SizedBox(height: 16.0),
                  const Text(
                    'idToken:',
                    style: TextStyle(
                      fontSize: 24.0,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  Text('${idToken.value}'),
                  const SizedBox(height: 16.0),
                  const Text(
                    'refreshToken:',
                    style: TextStyle(
                      fontSize: 24.0,
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                  Text('${refreshToken.value}'),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }

  _onError(BuildContext context, String? error) {
    var snackBar = SnackBar(
      content: Text(error ?? ''),
      backgroundColor: Colors.redAccent,
    );
    ScaffoldMessenger.of(context).showSnackBar(snackBar);
  }

  bool _onKeepLoading(String? url) =>
      url?.startsWith(params.redirectUrl) ?? false;
}

gabrielpatricksouza avatar Apr 29 '25 14:04 gabrielpatricksouza

Hi @unleed, any news?

gabrielpatricksouza avatar May 07 '25 17:05 gabrielpatricksouza