jaguar_oauth

OAuth interceptors for Jaguar

Usage

A simple usage example:

import 'dart:async';
import 'package:jaguar_reflect/jaguar_reflect.dart';
import 'package:jaguar/jaguar.dart';
import 'package:jaguar_oauth/jaguar_oauth.dart';
import 'package:oauth2/oauth2.dart' as oauth2;

const JaguarOauth2Config facebook = const JaguarOauth2Config();

@RouteGroup(path: '/auth')
class AuthRoutes {
  @Get(path: '/fb/authreq')
  @WrapOAuth2Req(null, makeParams: const {
    #config: const MakeParamFromMethod(#facebook),
  })
  void fbAuthReq() {}

  @Get(path: '/fb/authorized', mimeType: 'application/json')
  @WrapOAuth2Authorized(null, makeParams: const {
    #config: const MakeParamFromMethod(#facebook),
  })
  Future<String> fbAuthorized(
      @Input(OAuth2Authorized) oauth2.Client client) async {
    final resp = await client.get('https://graph.facebook.com/v2.8/me');
    return resp.body;
  }

  JaguarOauth2Config facebook() => new JaguarOauth2Config(
      key: Settings.getString('facebook_oauth_key'),
      secret: Settings.getString('facebook_oauth_secret'),
      authorizationEndpoint: 'https://www.facebook.com/dialog/oauth',
      tokenEndpoint: 'https://graph.facebook.com/v2.8/oauth/access_token',
      callback: Settings.getString('baseurl') + '/api/auth/fb/authorized',
      scopes: ['email']);
}

@Api(path: '/api')
class MyApi {
  @Group()
  final AuthRoutes auth = new AuthRoutes();
}

main(List<String> args) async {
  Settings.parse(args);
  Configuration conf = new Configuration();
  conf.addApi(new JaguarReflected(new MyApi()));

  await serve(conf);
}

Features and bugs

Please file feature requests and bugs at the issue tracker.

Libraries

jaguar_oauth

Support for doing something awesome.