Another Flutter OAuth package for simplifying OAuth operations
Originally tested with small collection of services such as:
If there is an issue with a specific service you are trying to work with, feel free to file an issue. :)
Performing authorization for an API is pretty easy, in most cases you just need to do the following:
final OAuth flutterOAuth = new FlutterOAuth(
new Config(
"https://unsplash.com/oauth/authorize",
"https://unsplash.com/oauth/token",
"YOUR_CLIENT_ID",
"YOUR_CLIENT_SECRET",
"http://localhost:8080",
"code"
)
);
This allows you to pass in an Authorization URL, Token Request URL, Your Applications Client ID, Your Applications Client Secret, Redirect URL and the response type.
This should satisfy most requests, but if not then you can pass in other optional parameters for:
contentType
- This allows you to change the content type for the request. For example, when using the Spotify API you need to set the contentType toapplication/x-www-form-urlencoded
final OAuth flutterOAuth = new FlutterOAuth(
new Config(
...,
contentType: "application/x-www-form-urlencoded"
)
);
parameters
- Add your own parameters that this library may not support (yet!). For example, when using the GitHub API you may send a state string and scopes to request authorization for.
Map<String, String> customParameters = {"state": "SOME_RANDOM_SECURE_STRING", "scope": "public_repo"};
final OAuth flutterOAuth = new FlutterOAuth(
new Config(
...,
parameters: customParameters
)
);
headers
- Some services may require you to send a custom header, such asAuthorization
.
Map<String, String> headers = {"Authorization": "Basic SOME_BASE_64_STRING"};
final OAuth flutterOAuth = new FlutterOAuth)
new Config(
...,
headers: headers
)
);
Then once you have an OAuth instance, you may simply call the performAuthorization()
method like so to retrieve a Token:
Token token = await flutterOAuth.performAuthorization();
String accessToken = token.accessToken;
Add the following you your pubspec.yaml dependancies:
dependencies:
easy_oauth: "^1.0.0"
Kevin Seqaud for his awesome blog post on Flutter OAuth
The Flutter Webview plugin, which carrys this library on it's back.