SSO package for studCloud project

Clone this repo:
  1. c009ea0 Update README.md by Anton Zuev · 6 years ago 1.4.0-express.js master
  2. ce45055 1.4.0 by Anton Zuev · 6 years ago
  3. bb4704d 1.4.0 by Anton Zuev · 6 years ago
  4. 9cc7f2c 1.3.6 by Anton Zuev · 6 years ago
  5. b14f82e 1.3.6 by Anton Zuev · 6 years ago

SSO package for StudCloud project

StudCloud.SSO - пакет, который упрощает операции, связанные с авторизацией клиентов.
Всю работу с cookie и сессиями можно поручить пакету.
Для каждого запроса создается контекст:
1. уровень авторизации(0-4):
0 - unauthorized 1 - authorized 2 - mail submitted 3 - mobile submitted 4 - document submitted 2. объект user user - authLevel > 0 undefined - authLevel == 0 3. changePasswordToken: string - allow to change password(value is key) undefined - not allow to change password Также с помощью него можно проверить уровень авторизации:
1. authLevel >= required - пропускаем дальше
2. authLevel < required - ошибка(401 или 405)

Installation

npm install @anzuev/studcloud.sso --save

Usage

let SSO = require('sso');


//...express app
//before use make sure that mongoose.UsersUri, mongoose.PSSUri and mongoose.SSOUri setted in config
SSO.init();
	
//basic work withSession, now it is express-session middleware
app.use(SSO.getSessionsMiddleware());
    
//load user context
app.use(SSO.getContextMiddleware());

//... express app


//... routes file
router.get('/', SSO.checkAuthMiddleware, function(req, res, next) {
   res.render('index', { title: 'Express' });
});
/*
    available checks:
        - checkAuthMiddleware
        - checkMailActivationMiddleware
        - checkMobileActivationMiddleware
        - checkDocumentActivationMiddleware
    */
//... routes file

Public Methods

signUp

Description

  • In:
    • authData object
      • name
      • surname
      • mail
      • password
  • Out:
    • user object from collection 'users'
    • ValidationError if data hasn't passed validation
      • code = 400
      • message = 'Mail is incorrect' or 'Password is too weak' or 'Incorrect personal info'
    • AuthError if user with such mail already exists in collection
      • code = 400
      • message = mail {some mail} already in use

Example

// sso already defined and configured

let authData = {
		name: "Anton",
		password: "sdkmskdmsf",
		surname: "Zuev",
		mail: "anzuev@bk.ru"
	};
let user = yield sso.signUp(authData);

signIn

Description

  • In:
    • authData object
      • mail
      • password
  • Out:
    • user object from collection 'users'
    • AuthError if no user found by mail
      • code = 401
      • message = 'Incorrect mail'
    • AuthError if password isn't correct
      • code = 401
      • message = 'Incorrect password'
    • DbError if something bad occured in database
      • code = 500
      • message = ''
      • err - error from database

Example

// sso already defined and configured

let authData = {
		name: "Anton",
		password: "sdkmskdmsf"
	};
let user = yield sso.signIn(authData);

confirmMail

Description

  • In:
    • mail
    • key
  • Out:
    • true if everything allright
    • ValidationError if no key passed
      • code = 400
      • message = 'Is is forbidden to use an empty key'
    • AuthError if no user found by mail and this key
      • code = 403
      • message = 'Confirmation failed'
    • DbError if something bad occured in database
      • code = 500
      • message = ''
      • err - error from database

Example

// sso already defined and configured

let result = yield sso.confirmMail('anzuev@bk.ru', '03df24bcce1e45b231876fe5b2c405b0a4940ebc');

confirmMobile

Description

  • In:
    • mail
    • phone
    • key
  • Out:
    • true if everything allright
    • ValidationError if no key passed
      • code = 400
      • message = 'Is is forbidden to use an empty key'
    • AuthError if no user found by mail and this key
      • code = 403
      • message = 'Confirmation failed'
    • DbError if something bad occured in database
      • code = 500
      • message = ''
      • err - error from database

Example

// sso already defined and configured

let result = yield sso.confirmMobile('anzuev@bk.ru', '+79210939059', '03df24bcce1e45b231876fe5b2c405b0a4940ebc');

setPasswordKey

Description

  • In:
    • mail
  • Out:
    • object if everything is allright
      • mail
      • key
    • ValidationError if no mail passed
      • code = 400
      • message = 'Is is forbidden to use an empty mail'
    • AuthError if no user found by mail
      • code = 403
      • message = 'No user found by mail {some mail}'
    • DbError if something bad occured in database
      • code = 500
      • message = ''
      • err - error from database

Example

// sso already defined and configured

let res = yield sso.setPasswordKey(anzuev@bk.ru);

setPassword

Description

  • In:
    • mail
    • key
    • newPassword
  • Out:
    • true if everything is allright
    • ValidationError if no key passed
      • code = 400
      • message = 'Is is forbidden to use an empty key'
    • AuthError if no user found by mail and key
      • code = 403
      • message = "Forbidden to set password by mail '{some mail}' and key='{some key}'"
    • DbError if something bad occured in database
      • code = 500
      • message = ''
      • err - error from database

Example

// sso already defined and configured

let res = yield sso.setPassword(anzuev@bk.ru, '03df24bcce1e45b231876fe5b2c405b0a4940ebc');

History

First version - 1.0.0
Current version - 1.4.0