The Protevus Platform: Unified Full-Stack Development https://protevus.com
Find a file
2019-01-05 18:55:12 -05:00
.idea preserve existing user 2018-06-27 13:17:44 -04:00
example 2.0.3 2018-12-09 11:29:15 -05:00
lib 2.1.1 2019-01-05 18:54:48 -05:00
test 2.1.1 2019-01-05 18:54:48 -05:00
.gitignore Ignore .dart_tool 2018-07-12 13:22:16 -04:00
.travis.yml 1.1.1 2018-06-27 12:36:31 -04:00
analysis_options.yaml external auth opts 2019-01-04 10:47:01 -05:00
CHANGELOG.md 2.1.1 2019-01-05 18:54:48 -05:00
LICENSE Initial commit 2016-05-02 19:39:57 -04:00
pubspec.yaml Add pkg:collection dep 2019-01-05 18:55:12 -05:00
README.md Update README 2018-09-11 18:12:15 -04:00

angel_auth

Pub build status

A complete authentication plugin for Angel. Inspired by Passport.

Wiki

Click here.

Bundled Strategies

  • Local (with and without Basic Auth)
  • Find other strategies (Twitter, Google, OAuth2, etc.) on Pub!!!

Example

Ensure you have read the wiki.

configureServer(Angel app) async {
  var auth = new AngelAuth();
  auth.serializer = ...;
  auth.deserializer = ...;
  auth.strategies['local'] = new LocalAuthStrategy(...);
  
  // POST route to handle username+password
  app.post('/local', auth.authenticate('local'));
  
  // Use a comma to try multiple strategies!!!
  //
  // Each strategy is run sequentially. If one succeeds, the loop ends.
  // Authentication failures will just cause the loop to continue.
  // 
  // If the last strategy throws an authentication failure, then
  // a `401 Not Authenticated` is thrown.
  var chainedHandler = auth.authenticate(
    ['basic','facebook'],
    authOptions
  );
  
  // Apply angel_auth-specific configuration
  await app.configure(auth.configureServer);
  
  // Middleware to decode JWT's...
  app.use(auth.decodeJwt);
}

Default Authentication Callback

A frequent use case within SPA's is opening OAuth login endpoints in a separate window. angel_client provides a facility for this, which works perfectly with the default callback provided in this package.

configureServer(Angel app) async {
  var handler = auth.authenticate(
    'facebook',
    new AngelAuthOptions(callback: confirmPopupAuthentication()));
  app.get('/auth/facebook', handler);
  
  // Use a comma to try multiple strategies!!!
  //
  // Each strategy is run sequentially. If one succeeds, the loop ends.
  // Authentication failures will just cause the loop to continue.
  // 
  // If the last strategy throws an authentication failure, then
  // a `401 Not Authenticated` is thrown.
  var chainedHandler = auth.authenticate(
    ['basic','facebook'],
    authOptions
  );
}

This renders a simple HTML page that fires the user's JWT as a token event in window.opener. angel_client exposes this as a Stream:

app.authenticateViaPopup('/auth/google').listen((jwt) {
  // Do something with the JWT
});