Authentication tools for Dart Frog apps.
dart pub add frog_authTo support Basic authentication, simply add the basicAuthentication middleware:
Handler middleware(Handler handler) {
return handler.use(
basicAuthentication(
retrieveUser: (context, username, password) async {
// TODO Retrieve user by username/password
},
),
);
}The retrieveUser callback should be used to lookup the user using the given username and password. If no user is found with the given credentials, you should return null.
If a non-null user is returned by the retrieveUser callback, it will be provided to the current request context and can be retrieved using context.read().
retrieveUser can return an object of any type extending Object, so should be flexible enough to work with any database system.
To support Bearer authentication, simply add the bearerAuthentication middleware:
Handler middleware(Handler handler) {
return handler.use(
bearerAuthentication(
retrieveUser: (context, token) async {
// TODO Retrieve user by token
},
),
);
}The retrieveUser callback should be used to lookup the user using the given token. If no user is found with the given token, you should return null.
If a non-null user is returned by the retrieveUser callback, it will be provided to the current request context and can be retrieved using context.read().
retrieveUser can return an object of any type extending Object, so should be flexible enough to work with any database system.