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!
Libraries
- azure_ad_oauth
- jwt
- model/config
- model/token
- request/token_refresh_request
- request/token_request
- request_code/platforms/request_code_ios
- request_code/platforms/request_code_unsupported
- request_code/platforms/request_code_web
- request_code/request_code
- request_token
- storage/auth_storage
- storage/i_storage
- storage/platforms/storage_native
- storage/platforms/storage_unsupported
- storage/platforms/storage_web