oauth_dio 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 83

oauth_dio #

A customizable oauth client with token storage and interceptors for dio.

Getting Started #

Instantiate a new OAuth Client:

// myclient.dart
import 'package:oauth_dio/oauth_dio.dart';

final oauth = OAuth(
      tokenUrl: '<YOUR TOKEN URL>',
      clientId: '<YOUR CLIENT ID>',
      clientSecret: '<YOUR SECRET>');

Obtaining an access token using username and password:

OAuthToken token = oauth.requestToken(
    grantType: 'password',
    username: '<YOUR USERNAME>',
    password: '<YOUR PASSWORD>'
).then((token) {

Updating access token using a refresh token:

OAuthToken token = oauth.requestToken(
    grantType: 'refresh_token',
    refreshToken: '<YOUR REFRESH TOKEN>'
).then((token) {

Configuring Dio to send access tokens: #

Instantiate a new OAuth Client with a permanent storage, by default oauth is configured with memory storage.

In this example we will use the flutter_secure_storage plugin to store the token on the device's keychain.

// myclient.dart
import 'package:oauth_dio/oauth_dio.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';

class OAuthSecureStorage extends OAuthStorage {
  final FlutterSecureStorage storage;
  final accessTokenKey = 'accessToken';
  final refreshTokenKey = 'refreshToken';

  Future<OAuthToken> fetch() async {
    return OAuthToken(
        accessToken: await storage.read(key: accessTokenKey),
        refreshToken: await storage.read(key: refreshTokenKey);

  Future<OAuthToken> save(OAuthToken token) async {
    await storage.write(key: accessTokenKey, value: token.acessToken);
    await storage.write(key: refreshTokenKey, value: token.refreshToken);
    return token;

  Future<void> clear() async {
    await storage.delete(key: accessTokenKey);
    await storage.delete(key: refreshTokenKey);

final oauth = OAuth(
    tokenUrl: '<YOUR TOKEN URL>',
    clientId: '<YOUR CLIENT ID>',
    clientSecret: '<YOUR SECRET>',
    storage: OAuthSecureStorage()

final authenticadedDio = Dio()
authenticadedDio.interceptors.add(BearerInterceptor(oauth: oauth))

authenticadedDio.get('/my/protected/resource').then((response) {

Feedback #

Please feel free to give me any feedback helping support this package!

[0.0.1] - TODO: Add release date. #

  • TODO: Describe initial release.


import 'package:oauth_dio/oauth_dio.dart';

void main() {
  final oauth = OAuth();

  oauth.requestToken(grantType: 'password', username: 'foo', password: 'bar').then((token) {
    print('AccessToken: ${token.accessToken}');
    print('RefreshToken: ${token.refreshToken}');

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  oauth_dio: ^0.1.2

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:oauth_dio/oauth_dio.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 9, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart


  • oauth_dio that is a package requiring null.

Health issues and suggestions

Document public APIs. (-0.33 points)

43 out of 44 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
dio ^3.0.9 3.0.9
flutter 0.0.0
Transitive dependencies
charcode 1.1.3
collection 1.14.12 1.14.13
http_parser 3.1.4
meta 1.1.8 1.2.1
path 1.7.0
sky_engine 0.0.99
source_span 1.7.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies