jaguar_oauth 2.1.1

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 0

jaguar_oauth

OAuth interceptors for Jaguar.

JaguarOauth2 provides an easy way to initiate an OAuth2 authorization request and handle the authorization response callback.

Example

@Api(path: '/auth')
class AuthRoutes {
  /// Route that initiates the OAuth2 authorization request by redirecting to
  /// authorization endpoint
  @Get(path: '/fb/authreq')
  Response<Uri> fbAuthReq(ctx) => facebook.initiateRequest(ctx);

  /// Route that handles OAuth2 authorization response callback
  @Get(path: '/fb/authorized', mimeType: 'application/json')
  Future<String> fbAuthorized(Context ctx) async {
    // Get the [Client] from authorization response callback
    oauth2.Client client = await facebook.handleResponse(ctx);
    // Use Facebook OAuth2 APIs
    final resp = await client.get('https://graph.facebook.com/v2.8/me');
    return resp.body;
  }

  /// Facebook OAuth2 configuration
  JaguarOauth2 get facebook => new JaguarOauth2(
      key: fbOauthKey,
      secret: fbOauthSecret,
      authorizationEndpoint: 'https://www.facebook.com/dialog/oauth',
      tokenEndpoint: 'https://graph.facebook.com/v2.8/oauth/access_token',
      callback: baseUrl + '/api/auth/fb/authorized',
      scopes: ['email']);
}

Example usage outside Jaguar routes

main(List<String> args) async {
  // Create the OAuth2 config
  final config = new JaguarOauth2(
      key: fbOauthKey, // Facebook OAuth key
      secret: fbOauthSecret, // Facebook OAuth secret
      authorizationEndpoint: 'https://www.facebook.com/dialog/oauth',
      tokenEndpoint: 'https://graph.facebook.com/v2.8/oauth/access_token',
      callback: 'http://localhost:5555/api/auth/fb/login/authorized',
      scopes: ['email']);

  // Print the authorization url
  print('Authorization url: ');
  print(config.authorizationUrl);

  print('Open the authorization URL in the browser.');
  print('Get the response code from Facebook.');

  // Get the response code
  stdout.write('Enter the code: ');
  String code = stdin.readLineSync();

  // Get HTTP [Client] from authorization response
  final Client client = await config.handleResponseWithParam({'code': code});

  // Fetch user profile
  final resp = await client.get('https://graph.facebook.com/v2.8/me');
  print(resp.body);
  exit(0);
}

Changelog

0.2.0

  • Moved to Jaguar 0.6.x
  • Helper functions rather than Interceptors

Use this package as a library

1. Depend on it

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


dependencies:
  jaguar_oauth: ^2.1.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:jaguar_oauth/jaguar_oauth.dart';
  
Version Uploaded Documentation Archive
2.1.1 May 20, 2018 Go to the documentation of jaguar_oauth 2.1.1 Download jaguar_oauth 2.1.1 archive
2.0.1 May 20, 2018 Go to the documentation of jaguar_oauth 2.0.1 Download jaguar_oauth 2.0.1 archive
0.2.0 Nov 7, 2017 Go to the documentation of jaguar_oauth 0.2.0 Download jaguar_oauth 0.2.0 archive
0.1.0 Jun 7, 2017 Go to the documentation of jaguar_oauth 0.1.0 Download jaguar_oauth 0.1.0 archive
0.0.2 Feb 19, 2017 Go to the documentation of jaguar_oauth 0.0.2 Download jaguar_oauth 0.0.2 archive
0.0.1 Feb 8, 2017 Go to the documentation of jaguar_oauth 0.0.1 Download jaguar_oauth 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
0
Learn more about scoring.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.24.0 <2.0.0