azure_ad_oauth 0.0.1-dev.1 azure_ad_oauth: ^0.0.1-dev.1 copied to clipboard
Flutter Azure AD oAuth.
Azure AD oAuth client. #
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.
How to use this plugin #
-
Copy
authenticator.dart
file from the example's lib folder and provide yourtenantId
andclientId
values, update other settings as necessary. This class is using singleton pattern withChangeNotifier
, so you can use it anywhere in your app. -
Provide
context
to 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.
Web setup: #
Please note: web auth done in popup only. Due to some browser security restrictions, embedding auth screen in
iframe
tag 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.html
file to yourweb
folder with the following content:
<script>
window.opener.postMessage(window.location.href, '*');
</script>
You are done!