https://github.com/cometkim/fastify-auth0-login
A Fastify plugin for easily adding login feature via Auth0's Authorization Code Flow
https://github.com/cometkim/fastify-auth0-login
Last synced: 4 months ago
JSON representation
A Fastify plugin for easily adding login feature via Auth0's Authorization Code Flow
- Host: GitHub
- URL: https://github.com/cometkim/fastify-auth0-login
- Owner: cometkim
- License: mit
- Archived: true
- Created: 2023-03-01T11:19:46.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-08-02T09:53:45.000Z (almost 2 years ago)
- Last Synced: 2024-10-29T14:38:56.899Z (over 1 year ago)
- Language: TypeScript
- Size: 2.38 MB
- Stars: 7
- Watchers: 2
- Forks: 2
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fastify-auth0-login
A Fastify plugin for easily adding login feature via Auth0's [Authorization Code Flow](https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow).
> [!NOTE]
> This demonstrates bare minimum implementation for session-based authentication with a external provider. Since its lack of capabilities, I'd like to recomment not to use for your production. Instead, consider using some other frameworks such as [Auth.js](https://authjs.dev/) or [account-js](https://www.accountsjs.com/).
## Prerequisites
- Fasyify v4.x+
- [@fastify/cookie](https://github.com/fastify/fastify-cookie)
## Usage
First, you need to create a Auth0 application.
Confirm the `Domain`, `Client ID`, and `Client Secret` then set you application's `Login URL`, `Allowed Callback URL`, and `Allowd Web Origins`.
For example to set for `https://localhost:3000`,

Then configure your Fastify app with this plugin and `@fastify/cookie` like this:
```ts
import FastifyCookie from '@fastify/cookie';
import FastifyAuth0Login from 'fastify-auth0-login';
app.register(FastifyCookie, {
secret: COOKIE_SECRET,
});
app.register(FastifyAuth0Login, {
auth0: {
domin: YOUR_AUTH0_DOMAIN,
clientId: YOUR_AUTH0_CLIENT_ID,
clientSecret: YOUR_AUTH0_CLIENT_SECRET,
},
verifySession: (_req, sessionId) => {
return findSession(sessionId);
},
confirmSession: (_req, sessionId, idTokenClaims) => {
return findOrCreateSession(sessionId, idTokenClaims);
},
});
```
Now you can initiate auth flow by GET `/auth/request`.
```html
Login with Auth0
```
## LICENSE
MIT