0.0.2 • Published 2 years ago
zju-authenticator v0.0.2
zju-authenticator
Helper utilities for login to and get user information from the Zhejiang University Unified Identity Authentication Platform (浙大统一身份认证平台).
Usage
CLI
Use command line arguments:
❯ npx zju-authenticator -u username -p password
Logged in successfully, the user information is below:
{
userId: 00000,
loginName: '...',
userName: '...',
// ...
}
Or let zju-authenticator
prompts you with questions:
❯ npx zju-authenticator
✔ Username: username
✔ Password: password
Logged in successfully, the user information is below:
{
userId: 00000,
loginName: '...',
userName: '...',
// ...
}
API
const { ZjuAuthenticator } = require('zju-authenticator')
// or in ES Module format:
// import { ZjuAuthenticator } from 'zju-authenticator'
const zjuAuthenticator = new ZjuAuthenticator({
username: '...',
password: '...'
})
zjuAuthenticator
.login()
.then(userInfo => {
console.log(userInfo)
// {
// userId: 00000,
// loginName: '...',
// userName: '...',
// // ...
// }
})
.catch(err => {
if (err.message === ZjuAuthenticator.STATUS.INCORRECT_CREDENTIALS) {
console.error('Incorrect credentials, please check your input!')
} else if (err.message === ZjuAuthenticator.STATUS.UNEXPECTED_ERROR) {
console.error('Unexpected error at:', err.stack)
} else {
console.error(err.stack)
}
})
Disclaimer
Never disclose your username and password publicly or to someone you do not trust, Remember to add your secret files to .gitignore
and as secrets.