A flutter library for OAuth2 - the industry-standard protocol for authorization
Clone or download
Latest commit 23600ff Dec 31, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea Strip the example Dec 3, 2018
example Updated the examples Dec 2, 2018
lib Make user-agent and client secret named optional Dec 2, 2018
.gitignore Updated authors Dec 2, 2018
.metadata Add MIT license Dec 2, 2018
CHANGELOG.md Add MIT license Dec 2, 2018
LICENSE Initial commit Dec 2, 2018
README.md Update README.md Dec 31, 2018
oh_auth_2.iml Add MIT license Dec 2, 2018
pubspec.lock Add MIT license Dec 2, 2018
pubspec.yaml Bumped the version Dec 2, 2018

README.md

OhAuth2

OhAuth2 is a Flutter library for OAuth2 - the industry-standard protocol for authorization.

Disclaimer: This library has been tested with a few services like Reddit and Strava. If you find OhAuth2 to be incompatible with a service you're trying to use this library with, please open an Issue or create a PR

Installation

Installing OhAuth2 is simple using Dart's package management system https://pub.dartlang.org/packages/oh_auth_2#-installing-tab-.

Getting Started

(Assuming you already have your OAuth credentials)

To retrieve the access token:

import 'dart:async';
import 'package:oh_auth_2/authenticator.dart';
import 'package:oh_auth_2/models/token.dart';

Future<Token> tokenResult = Authenticator(context)
    .getAccessToken(
        AuthenticationConfig.REDIRECT_URI,
        AuthenticationConfig.AUTH_URL,
        AuthenticationConfig.ACCESS_TOKEN_URL,
        AuthenticationConfig.CLIENT_ID,
        userAgent: AuthenticationConfig.USER_AGENT, //optional
        clientSecret: AuthenticationConfig.CLIENT_SECRET, //optional
)
    .then((token) {
  this.token = token;
  debugPrint(token.toJson().toString());
});

To refresh the access token:

import 'dart:async';
import 'package:oh_auth_2/authenticator.dart';
import 'package:oh_auth_2/models/token.dart';

Token token = await Authenticator(context).refreshAccessToken(
    AuthenticationConfig.ACCESS_TOKEN_URL,
    this.token.refreshToken,
    AuthenticationConfig.CLIENT_ID,
    userAgent: AuthenticationConfig.USER_AGENT, //optional
    clientSecret: AuthenticationConfig.CLIENT_SECRET, //optional
);
this.token.accessToken = token.accessToken;
debugPrint("Refreshed access token " + token.accessToken);

To revoke the access/refresh token:

import 'dart:async';
import 'package:oh_auth_2/authenticator.dart';
import 'package:oh_auth_2/models/token.dart';

bool isRevoked = await Authenticator(context).revokeAccessToken(
    AuthenticationConfig.REVOKE_TOKEN_URL,
    token.refreshToken,
    AuthenticationConfig.CLIENT_ID,
    userAgent: AuthenticationConfig.USER_AGENT, //optional
    clientSecret: AuthenticationConfig.CLIENT_SECRET //optional
);
debugPrint("Revoked access token " + (isRevoked.toString()));

Contact

License

OhAuth2 is provided under a MIT License. Copyright (c) 2018 Murtaza Akbari.