Skip to content

ptrbrynt/frog_auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Frog Auth

Authentication tools for Dart Frog apps.

Installation

Pub Version

dart pub add frog_auth

Usage

Basic Authentication

To 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.

Bearer Authentication

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.

About

Authentication for Dart Frog apps

Topics

Resources

License

Stars

Watchers

Forks

Languages