moh-auth-plus v1.0.0
moh-auth-plus
The auth plus lib to make auth with role, oauth, custome auth easily and reuseable.
Usage
User should inject the following methhod to make functions works.
- Init the
AuthPluswith your own bussiness logic
authPlus = AuthPlus({
tokenTTL: xxx,
basicAuth: (username, password) => {},
customLogin: (openId) => {},
fetchInfo: (user) => {},
createToken: (user, info) => {},
authByToken: (token) => {},
refreshToken: (refreshToken) => {},
revokeToken: (token) => {},
customRevokeToken: (username) => {}
})- Call the authPlus to handle auth logic
const token = await authPlus.basicLogin('ole3021', 'test1234')
const token = await authPlus.customLogin('WeChatOpenId')
const token = await authPlus.authenticate(currentToken.accessToken)
const token = await authPlus.refreshToken('refreshToken')
const result = await authPlus.logout(currentToken.accessToken)
const result = await authPlus.forceLogout('ole3022')
Inject base methods
A1 basicAuth: return valied user with
accountandpasswordinfo.(account, password) => Promise.resolve(user)A2 customAuth: return valied user with
customInfo.(customInfo) => Promise.resolve(user)B fetchInfo: return other related info with
user.*(user) => Promise.resolve(info)C createdToken: return token with
userandinfo.(user, *info) => tokenD authByToken: return
toeknwithhaccessToken.(accessToken) => tokenE refreshhToken: return new
tokenwithrefreshToken.(refreshToken) => tokenF1 revokeToken: return boolean with
accessToken.(accessToken) => booleanF2 customRevokeToken: return boolean with
userId.(info) => boolean(Use for scenario like admin cancel user access righ.)
Buildin helpers
encrypt: return encrypted password.
(password, *salt) => encryptedPasswordisVerified: return is password matchh the encrypted password.
(password, encryptedPassword) => boolean
Features
- basicLogin:
A1 -> *B -> C - customLogin:
A2 -> *B -> C - auth:
D - refreshhToken:
E - logout:
F1 - forceLogout:
F2
8 years ago