sso-oauth2-server
TypeScript icon, indicating that this package has built-in type declarations

0.0.12 • Public • Published

npm-template

npm package MIT last commit downloads week downloads total size dependencies

Npm publish Build status Quality Gate Bugs Coverage Code Smells Duplicated Lines (%) Maintainability Rating Reliability Rating Security Rating Technical Debt Vulnerabilities

npm-template

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.

  1. Get informations about needed auth Params
curl http://yourSSoAuth2ServerDomain:3010/customSubroute/authParams

-->
{
    params: {
        username: 'string',
        password: 'password',
    }
}
  1. 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);
  1. Your client

Contributors

The FireboltCasters

Contributors

Readme

Keywords

Package Sidebar

Install

npm i sso-oauth2-server

Weekly Downloads

8

Version

0.0.12

License

MIT

Unpacked Size

57.5 kB

Total Files

32

Last publish

Collaborators

  • fireboltcaster