Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/megaads-vn/express-sso-client
Nodejs Express SSO Client
https://github.com/megaads-vn/express-sso-client
Last synced: 10 days ago
JSON representation
Nodejs Express SSO Client
- Host: GitHub
- URL: https://github.com/megaads-vn/express-sso-client
- Owner: megaads-vn
- License: mit
- Created: 2024-10-28T03:02:14.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-10-30T03:35:12.000Z (2 months ago)
- Last Synced: 2024-12-15T08:53:10.106Z (24 days ago)
- Language: TypeScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# express-sso-client
`express-sso-client` is an Express middleware library for handling Single Sign-On (SSO) authentication with JWT token support for MegaAds.Vn. This library includes middleware to protect routes and an SSO callback handler that verifies tokens with an external server and sets them in secure cookies.
## Features
- Middleware for protecting routes with SSO authentication.
- SSO callback handler that verifies tokens with an external verification server.
- JWT token support with forced expiration.
- Secure token storage in cookies.
- Support Typescripts## Installation
Install `express-sso-client` and required dependencies:
```bash
npm install @megaads/express-sso-client
```## Usage
Use ssoMiddleware to protect routes. If a user is not authenticated, they are redirected to the SSO login page.```
const express = require('express');
const session = require('express-session'); // install if provider is session
const { ssoMiddleware, ssoRouterUrl } = require('@megaads/express-sso-client');const app = express();
app.use(session({ /* your config */ }));// please contact CTO MegaAds get configuration:
const ssoOptions = {
active: true,
provider: 'session' || 'jwt', // if provider is 'jwt' via header 'x-access-token' or 'authorization'
token_options: {}, // set if provider is 'jwt'
secret: 'random_string', // set if provider is 'jwt'
app_id: XXXX,
login_url: 'https://.../system/home/login',
logout_url: 'https://.../system/home/logout',
callback_url: 'http://localhost:3000/sso/callback', // my domain
auth_url: 'https://.../auth/sso',
redirect_url: 'http://localhost:3000', // set if provider is 'session'
};app.use(ssoMiddleware(ssoOptions, ['/admin']));
app.use(ssoRouterUrl(ssoOptions));app.get('/admin', (req, res) => {
// handler
res.send(`Admin, ${JSON.stringify(req.user)}`);
});app.get('/', (req, res) => {
res.send(`Hello, Guest!`);
});app.listen(3000, () => {
console.log('Server is running on port 3000');
});```
## Contact
- Email: [email protected]
- Skype: tuananhzippy