About
angel3_auth is, in many ways, a port of Passport to the Angel3 Framework.

Usage

1
// Of course, create an instance.
2
//
3
// A `jwtKey` is not required, but without a pre-established secret,
4
// JWT's will automatically be invalidated whenever the server restarts.
5
//
6
// If your `allowCookie` is `true` (`true` by default), then JWT's can also be carried within
7
// a `token` cookie. This can be annoying during the development stage, as it is difficult to remove
8
// cookies from Dartium.
9
//
10
// By convention, try to avoid cookies and session use whenever possible.
11
var auth = AngelAuth(jwtKey: 'MY_SECRET', allowCookie: false);
12
​
13
// The following two functions de/serialize a user from a JWT.
14
auth.serializer = (user) async => serializeUserToId();
15
auth.deserializer = (id) async => deserializeUserFromId();
16
​
17
// Strategies are used to implement authentication methods
18
auth.strategies.add['local'] = LocalAuthStrategy((username, password) async {
19
return await findCorrespondingUser(username, password);
20
});
21
​
22
// Use `authenticate` to log users in
23
var app = Angel()..post('/auth/local', auth.authenticate('local'));
24
​
25
// Finally, call our instance as a plugin.
26
//
27
// This will a global middleware to decode JWT's and deserialize them,
28
// and also creates a route to refresh JWT's.
29
await app.configure(auth);
Copied!
Last modified 5mo ago
Copy link
Contents
Usage