keycloak_wrapper 0.0.1 keycloak_wrapper: ^0.0.1 copied to clipboard
Keycloak client adapter for Flutter.
Keycloak Wrapper #
Integrate Keycloak Single Sign-On (SSO) authentication into your Flutter apps seamlessly using this package. Tokens are automatically managed in the background, and when needed, you can easily access them without writing any extra code. A user authentication state stream is also provided for the app to listen to in order to stay in sync with authentication status changes.
đ Getting Started #
- AndroidX is required for this package. Starting from Flutter v1.12.13, newly created projects already enable AndroidX by default. In case your project was created prior to this Flutter version, please migrate it before using this package. You can follow this migration guide provided by the Flutter team.
đšī¸ Platform Configuration #
Android Setup #
Go to the build.gradle
file for your Android app to specify the custom scheme so that there should be a section in it that look similar to the following but replace <your_custom_scheme>
with the desired value.
...groovy
android {
...
defaultConfig {
...
manifestPlaceholders += [
'appAuthRedirectScheme': '<your_custom_scheme>'
]
}
}
Alternatively, the redirect URI can be directly configured by adding an intent-filter for AppAuth's RedirectUriReceiverActivity to your AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.my_app">
...
<activity
android:name="net.openid.appauth.RedirectUriReceiverActivity"
android:exported="true"
tools:node="replace">
<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="<your_custom_scheme>"
android:host="<your_custom_host>"/>
</intent-filter>
</activity>
...
Please ensure that value of <your_custom_scheme>
is all in lowercase as there've been reports from the community who had issues with redirects if there were any capital letters. You may also notice the +=
operation is applied on manifestPlaceholders
instead of =
. This is intentional and required as newer versions of the Flutter SDK has made some changes underneath the hood to deal with multidex. Using =
instead of +=
can lead to errors like the following.
Attribute application@name at AndroidManifest.xml:5:9-42 requires a placeholder substitution but no value for <applicationName> is provided.
If you see this error then update your build.gradle
to use +=
instead.
iOS Setup #
Go to the Info.plist
for your iOS/macOS app to specify the custom scheme so that there should be a section in it that look similar to the following but replace <your_custom_scheme>
with the desired value.
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string><your_custom_scheme></string>
</array>
</dict>
</array>
đ Usage #
The first step is to create an instance of the keycloak wrapper class.
final keycloakWrapper = KeycloakWrapper();
đ§ Troubleshooting #
P.S. Feel free to report any encountered issues at the Github repository page. Pull requests are very welcome in order to improve this package. Any contribution towards the maintenance of this open-source project is very much appreciated.