https://github.com/ptrbrynt/frog_auth
Authentication for Dart Frog apps
https://github.com/ptrbrynt/frog_auth
authentication dart dart-frog
Last synced: 4 months ago
JSON representation
Authentication for Dart Frog apps
- Host: GitHub
- URL: https://github.com/ptrbrynt/frog_auth
- Owner: ptrbrynt
- License: mit
- Created: 2022-08-17T14:14:11.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-11-04T21:56:01.000Z (over 3 years ago)
- Last Synced: 2025-10-23T04:39:45.162Z (8 months ago)
- Topics: authentication, dart, dart-frog
- Language: Dart
- Homepage:
- Size: 6.84 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Frog Auth
Authentication tools for [Dart Frog](http://dartfrog.vgv.dev) apps.
## Installation

```sh
dart pub add frog_auth
```
## Usage
### Basic Authentication
To support [Basic authentication](https://en.wikipedia.org/wiki/Basic_access_authentication), simply add the `basicAuthentication` middleware:
```dart
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](https://datatracker.ietf.org/doc/html/rfc6750), simply add the `bearerAuthentication` middleware:
```dart
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.