Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

flutter flutter logo oauth package

a flutter oauth package for performing user authentication for your apps.

i’ve tested this with a small collection of apis (buffer, strava, unsplash and github). if there is an issue with an api you are trying to work with, please file an issue 🙂

flutter oauth #1 app authorizing
flutter oauth #1 app authorizing

authorizing an application

performing authorization for an api is straight forward using the oauth package library. in most cases you
will just be able to use the following approach:

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, client id, 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, for spotify
    api authorization you need to use “application/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 out-of-the-box. for example,
    with the github api you can send a state string and scopes to gain 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 apis require you to send custom headers, such as an authorization header. use this
    parameter if you require this
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 can simply call the performauthorization() method like so to retrieve a token instance:

token token = await flutteroauth.performauthorization();
string accesstoken = token.accesstoken;

installing

to install flutter oauth, add the following you your pubspec.yaml dependancies:

dependencies:
  flutter_oauth: "^0.0.1"

download the full project for this post from the following button

this source is fully free for all time

download as zip


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.