microsoft / aad_b2c_webview

Azure AD B2C Embedded Webview is a very simple Flutter package that demonstrates how to use the embedded web view to sign in users with Azure AD B2C.
MIT License
32 stars 22 forks source link

Which redirect url should I use? #40

Open luancaius opened 5 months ago

luancaius commented 5 months ago

Hello, first, congrats on the project, it makes the user experience with azure ad b2c much better. I was trying to setup on my app, but I'm having trouble with the redirect url. For example if my bundle id is com.example.mobile and the redirect url on azure ad b2c for ios is msauth.com.example.mobile://auth, what should I replace that as redirect url? I tried to create a SPA redirect url on azure ad b2c, put a random url and it redirected after login, but I need to make it come back to the app instead of visiting another url. Any ideas on how to fix this? Thanks!

mohanajuhi166 commented 4 months ago

@luancaius does this work for you ?

final aadB2CRedirectURL = 'customScheme://your_bundle_id/auth';

mohanajuhi166 commented 4 months ago

have a look here: https://github.com/microsoft/aad_b2c_webview/issues/23

luancaius commented 4 months ago

@mohanajuhi166 I tried the following scenarios: Test 1 - Created web redirect on azure with redirect url as "https://bundle_id/auth" (set the same url on flutter) I also update my AndroidManifest.xml, adding this:

<intent-filter>
      <action android:name="android.intent.action.VIEW" />
      <category android:name="android.intent.category.DEFAULT" />
      <category android:name="android.intent.category.BROWSABLE" />
      <data android:scheme="https" android:host="<bundle_id>" android:pathPrefix="/auth" />
</intent-filter>

On IOS I got a null exception:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value
#0      ADB2CEmbedWebViewState.initState.<anonymous closure> (package:aad_b2c_webview/src/presentation/aad_b2c_webview.dart:94:63)
#1      WebKitWebViewController._webView.<anonymous closure>.<anonymous closure> (package:webview_flutter_wkwebview/src/webkit_webview_controller.dart:299:32)
<asynchronous suspension>

and on Android I got Webpage not available with the token response and net::ERR_NAME_NOT_RESOLVED. I wonder if I have to use any deep link here to redirect to my main page.

Test 2 - Same as 1 for url "https://.b2clogin.com/oauth2/nativeclient" Didnt work at all, even updating the intent filter.

What I have working is using fluuter_appauth 6.0.6 and the following settings on azure and flutter: IOS redirect url "msauth.://auth" Android redirect url "msauth:///signature_hash"

Do I need to delete the other redirects and leave just the Web one? Also if it's not a lot of work, an example using duende identity like https://pub.dev/packages/flutter_appauth/example would be very helpful. Thank you!

mohanajuhi166 commented 4 months ago

@luancaius at the moment , the web redirect should work so you can try deleting those . Will look into the implementation by https://pub.dev/packages/flutter_appauth/example and implement it.

luancaius commented 4 months ago

Tried deleting all others, and it was loading the login page, but still not working. My redirect url was https://bundle_id/auth. On IOS the login didn't redirect and on Android I got Webpage not available with the token, like before.