Git Product home page Git Product logo

ohauth2's Introduction

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.

ohauth2's People

Contributors

scimetfoo avatar

Stargazers

Wade avatar Shubhendu avatar Aleks avatar Nanang Prasetya avatar Daniel avatar Malik Motani avatar Nazym avatar  avatar  avatar  avatar ZHOU DENGFENG avatar  avatar Chris Johnson avatar Leo van Haaren avatar Sascha Kiefer avatar Anushka Paradkar avatar Ryan Rony Dsilva avatar Burhanuddin Rampurawala avatar  avatar kazuki229 avatar Tim Hyde avatar  avatar mono — Masayuki Ono avatar Vitaliy Vostrikov avatar NeXT avatar Amr ahmed avatar Andrejs Agejevs avatar Kosta Stoupas avatar Ariel Martinez Viera avatar Dyego Vieira avatar Ken Sykora avatar

Watchers

 avatar

ohauth2's Issues

Сan't have a part-of directive

error: The imported library ''package:oh_auth_2/models/token_generated.dart'' can't have a part-of directive. (import_of_non_library at [flutter_adal_testing] lib/example_view.dart:6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.