sso-oauth2-server
v0.0.12
Published
A simple package for a single sing-on (SSO) server
Downloads
4
Readme
About
A simple server package for npm based on https://github.com/ankur-anand/simple-sso
Usage
index.js
import SsoAuth2Server from '../SsoAuth2Server';
import Logger from '../Logger';
import {Connector, UrlHelper} from 'studip-api';
const STUDIP_AUTH_METHOD = async (body, client_id, scope, query) => {
Logger.log('Authentification: start');
const username = body.username;
const password = body.password;
//auth or throw error
return user;
};
const requiredLoginParams = {
username: 'string',
password: 'password',
};
const redirectMode = true;
const port = 3010;
const route = '/<customSubroute>';
const sessionSecret = 'keyboard cat';
const jwtSecret = 'MySuperSecret';
const ssoServer = new SsoAuth2Server(
redirectMode,
port,
route,
sessionSecret,
jwtSecret,
STUDIP_AUTH_METHOD,
requiredLoginParams
);
ssoServer.registerService(
'https://<yourOriginDomain>.com',
'<myAuthClientName>',
'<yourSecret>'
);
ssoServer.start();
Routes
You can always see your registered Routes by calling:
ssoServer.getAllRegisteredRoutes();
By default the routes will be:
LOGIN: localhost/<customSubroute>/login
AUTH_PARAMS: localhost/<customSubroute>/authParams
AUTH_PARAMS: localhost/<customSubroute>/verifytoken
PROFILE: localhost/<customSubroute>/getProfile
Client
A client can now authentificate.
- Get informations about needed auth Params
curl http://yourSSoAuth2ServerDomain:3010/customSubroute/authParams
-->
{
params: {
username: 'string',
password: 'password',
}
}
- Your client know knows what to send as body
let body = {username: 'me', password: 'mycat'};
let url = 'http://yourSSoAuth2ServerDomain:3010/customSubroute/login?';
url += 'client_id=sso_consumer&';
url += 'redirect_uri=<http://redirectURL..../callback>&'; //but url encoded
url += 'response_type=code&';
url += 'scope=email firstname lastname&';
url += 'state=<receivedStateFromOauthServer>';
axios.post(url, body);
- Your client
Contributors
The FireboltCasters