https://github.com/schamane/passport-forward-auth
Authentication strategy to support traefik forward-auth for Passport
https://github.com/schamane/passport-forward-auth
auth forward-auth passportjs traefik
Last synced: about 1 year ago
JSON representation
Authentication strategy to support traefik forward-auth for Passport
- Host: GitHub
- URL: https://github.com/schamane/passport-forward-auth
- Owner: schamane
- License: mit
- Created: 2020-08-29T18:31:05.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2021-09-03T21:59:21.000Z (over 4 years ago)
- Last Synced: 2025-03-01T03:33:11.677Z (over 1 year ago)
- Topics: auth, forward-auth, passportjs, traefik
- Language: TypeScript
- Homepage:
- Size: 398 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# passport-forward-auth
Small library for nodejs to use HTTP headers authentication behind traefik forward-auth.
## Example how to use it
```ts
import express, { Application } from 'express';
import { authenticate, use, initialize, Strategy } from 'passport';
import { ForwardAuthStrategy, VerifyFunction } from 'passport-forward-auth';
const port = 8082;
const authHeaders = ['X-ForwardUser', 'X-ForwardUserEmail'];
const app: Application = express();
const verifyFn: VerifyFunction = (verifyHeaders, done) => {
console.log('have user data found in headers', verifyHeaders);
return !verifyHeaders ? done(null) : done(null, { id: 'user_id' });
};
const createStrategy = (): Strategy => new ForwardAuthStrategy({ authHeaders }, verifyFn);
use(createStrategy());
app.use(initialize());
app.get('/auth/forward-auth', authenticate('forward-auth', { session: false }), (req, res) => {
res.send({ status: 'ok', user: req.user });
});
```