Comments (7)
Hi All,
We've tracked down what we were missing in our code now. Thank you all for the pointers!
Here's what we changed to fix the issue:
- Add the following
/android/app/src/main/AndroidManifest.xml
inside the tags:
<meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
<intent-filter android:autoVerify="true">
<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="myurl.com" />
</intent-filter>
- Change the redirect URL in our flutter code to
https://myurl.com/myappname
and add this as a redirect URL in the Azure B2C project - Our updated version of the
main.dart
file is now as follows:
import 'package:aad_b2c_webview/aad_b2c_webview.dart';
import 'package:flutter/material.dart';
import 'counterdemo.dart';
void main() {
runApp(const MyApp());
}
onRedirect(BuildContext context) {
Navigator.of(context).pushNamedAndRemoveUntil('/myappname', (Route<dynamic> route) => false);
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primaryColor: const Color(0xFF2F56D2),
textTheme: const TextTheme(
headlineLarge: TextStyle(
color: Colors.black,
fontSize: 32,
fontWeight: FontWeight.w700,
fontFamily: 'UberMove',
),
bodyLarge: TextStyle(
color: Color(0xFF8A8A8A),
fontSize: 17,
fontWeight: FontWeight.w400,
fontFamily: 'UberMoveText',
),
displayMedium: TextStyle(
fontSize: 18,
color: Colors.black,
fontWeight: FontWeight.w700,
fontFamily: 'UberMove',
),
),
),
debugShowCheckedModeBanner: false,
initialRoute: '/',
routes: {
// When navigating to the "/" route, build the Create Account widget.
'/': (context) => const LoginPage(),
'/myappname': (context) => const CounterDemo(),
},
);
}
}
class LoginPage extends StatefulWidget {
const LoginPage({super.key});
@override
State<LoginPage> createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
String? jwtToken;
String? refreshToken;
@override
Widget build(BuildContext context) {
const aadB2CClientID = "<app-id>";
const aadB2CRedirectURL = "https://myurl.com/myappname";
const aadB2CUserFlowName = "B2C_1_APPNAME_Signin";
const aadB2CScopes = ['openid', 'offline_access'];
const aadB2TenantName = "<tenantName>";
const aadB2CUserAuthFlow =
"https://$aadB2TenantName.b2clogin.com/$aadB2TenantName.onmicrosoft.com";
return Scaffold(
appBar: AppBar(
title: const Text("AAD B2C Login"),
backgroundColor: const Color(0xFF2F56D2)
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
/// Login flow
AADLoginButton(
userFlowUrl: aadB2CUserAuthFlow,
clientId: aadB2CClientID,
userFlowName: aadB2CUserFlowName,
redirectUrl: aadB2CRedirectURL,
context: context,
scopes: aadB2CScopes,
onAnyTokenRetrieved: (Token anyToken) {},
onIDToken: (Token token) {
jwtToken = token.value;
},
onAccessToken: (Token token) {
},
onRefreshToken: (Token token) {
refreshToken = token.value;
},
onRedirect: (context) => onRedirect(context),
),
/// Refresh token
TextButton(
onPressed: () async {
if (refreshToken != null) {
AzureTokenResponse? response =
await ClientAuthentication.refreshTokens(
refreshToken: refreshToken!,
tenant: aadB2TenantName,
policy: aadB2CUserAuthFlow,
clientId: aadB2CClientID,
);
if (response != null) {
refreshToken = response.refreshToken;
jwtToken = response.idToken;
}
}
},
child: const Text("Refresh my token"),
),
TextButton(
onPressed: () async {
Navigator.pushNamed(context, '/myappname');
},
child: const Text("Go To Counter Demo"),
)
],
),
),
);
}
}
from aad_b2c_webview.
Hi @craig-waite for aadB2CRedirectURL
instead of com.my.app.name://oauthredirect/
Can you please try changing it to to a standard weburl like this:
https://.b2clogin.com/oauth2/nativeclient
Let me know.
from aad_b2c_webview.
similar issue resolution:
#23
from aad_b2c_webview.
Hi @craig-waite for aadB2CRedirectURL instead of
com.my.app.name://oauthredirect/
Can you please try changing it to to a standard weburl like this:
https://.b2clogin.com/oauth2/nativeclient
Let me know.
Hi,
I've implemented the same sample scenario and used the suggested weburl: https://tenant-name.b2clogin.com/oauth2/nativeclient
As a result I am getting a blank page after authentication while the expectation is to be redirected to home page with a counter. Please advice.
from aad_b2c_webview.
Thanks for the help on this. I am now able to log in without the app showing an error. I do now get the issue experienced by @armache above, but I'm assuming that is just because I'm not routing correctly in the Flutter code. I will update here once I have a properly working prototype to share.
from aad_b2c_webview.
@craig-waite let me know. It just needs to route to one of the routes in flutter code.
from aad_b2c_webview.
@craig-waite this is great! I would encourage you to open a PR and provide this documentation for an OSS contribution. Let me know.!
from aad_b2c_webview.
Related Issues (18)
- Not able to logout user for azure b2c login HOT 2
- Forget Password back button click is not redirect to login screen. HOT 3
- Redirecting on IOS HOT 3
- Not compatible with the latest version of flutter
- Bug with login using web view - method call in the wrong place HOT 8
- Not compatible with webview_flutter ^4 HOT 1
- Add Support For Enable Keep Me Signed In Flow - Flutter Username Password autofill from next session if already added remember me option HOT 1
- Redirect uri HOT 3
- Please help on React Native b2c login HOT 2
- ERROR the request does not contains a client id parameter HOT 4
- The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
- When ios wrapper will be release HOT 3
- ResponseType as default / code throws error HOT 1
- Google Sign In issue HOT 1
- Google login error that says “403 disallowed_useragent,” HOT 1
- Library stops working after 0.0.51 for Android HOT 2
- Not getting access token HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aad_b2c_webview.