Fully automated oAuth client for Azure Active Directory. All you need to call is login(), logout(), and await OAuth.instance.token to get your token. Everything else is taken care of by the plugin behind the scenes.
-
Copy
authenticator.dartfile from the example's lib folder and provide yourtenantIdandclientIdvalues, update other settings as necessary. This class is using singleton pattern withChangeNotifier, so you can use it anywhere in your app. -
Provide
contextto the config berfore callinglogin()method something like so:
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: OAuth.instance..config.context = context,
builder: (context, _) {
...- Now you can call
login()andlogout()methods. To make authenticated calls - addAuthorizetion: Bearer ${await OAuth.instance.token}to your request headers.
Please note: web auth done in popup only. Due to some browser security restrictions, embedding auth screen in
iframetag is not possible.
- For local testing - register Web App in AAD and whitelist the following URL:
http://localhost:45678/authRedirect.html
- For local testing - add following config to your
launch.json:
{
"name": "Web Chrome",
"request": "launch",
"type": "dart",
"args": ["-d", "chrome","--web-port", "45678"],
},- Add
authRedirect.htmlfile to yourwebfolder with the following content:
<script>
window.opener.postMessage(window.location.href, '*');
</script>You are done!