ptpn4-adonis-sso
v0.1.3
Published
PTPN IV SSO Adonis Client Auth
Downloads
9
Readme
N4 SSO Client
Adonis Auth Extended for Private PTPN IV SSO Server
Installation
adonis install ptpn4-adonis-sso
or
npm i ptpn4-adonis-sso
Configuration
- Register
SsoAuthProvider
andIhcsProvider
instart/app.js
:
const providers = [
//...
'ptpn4-adonis-sso/providers/SsoAuthProvider',
'ptpn4-adonis-sso/ihcs/providers/IhcsProvider',
//...
]
- Add the SSO specific setting for SSO Server to
.env
file
SSO_APP_CODE=MYAPPCODE
SSO_CHECKPOINT_URL=https://my.sso_server.url/login?redirect=/sso/checkpoint/${SSO_APP_CODE}
SSO_LOGOUT_REDIRECT=https://my.sso_server.url
SSO_API_URL=https://myapi.sso_server.url:port/sso/
How To Use
- This route is mandatory. This route is related to SSO authentication
start/routes.js
Route.get('/', 'LoginController.index').middleware(['auth'])
Route.get('/sso', 'LoginController.redirect')
Route.get('/sso/checkpoint/', 'LoginController.checkpoint')
Route.get('/sso/logout', 'LoginController.logout')
Route.get('/logout', 'LoginController.logout')
Next Step
Create services.js
File in \config directory
'use strict'
/*
|--------------------------------------------------------------------------
| Services Configuration
|--------------------------------------------------------------------------
|
| This is general purpose file to define configuration for multiple services.
| The below config is for the ally provider. Make sure to save it inside
| config/services.js file.
|
| Happy Coding :)
|
*/
const Env = use('Env')
module.exports = {
ihcs: {
sso: {
appCode: Env.get('SSO_APP_CODE'),
checkpointUrl: Env.get('SSO_CHECKPOINT_URL'),
logoutRedirect: Env.get('SSO_LOGOUT_REDIRECT'),
apiUrl: Env.get('SSO_API_URL')
},
}
}
Next Step
- Create LoginController.js file in app/Controllers/Http
'use strict'
class LoginController {
async index ({ view, auth }) {
let data = {
user: auth.user
}
// console.log(auth.user)
try {
auth.getUser()
.then((value) => {
console.log(value)
})
} catch (error) {
return error.message
}
return view.render('welcome', data)
}
async redirect ({ ihcs, auth, response }) {
try {
if(await auth.check()) {
response.redirect('back')
} else {
await ihcs.driver('sso').redirect()
}
} catch (error) {
return error.message
}
}
async checkpoint ({ ihcs, auth, response }) {
try {
if(await auth.check()) {
response.redirect('/')
} else {
await auth._removeSession()
const ssoUser = await ihcs.driver('sso').getUser()
await auth.login(ssoUser)
response.redirect('back')
}
} catch (error) {
return error.message
}
}
async logout({ auth, response }) {
const Env = use('Env')
await auth.logout()
return response.redirect(Env.get('SSO_LOGOUT_REDIRECT'))
}
}
module.exports = LoginController
- Please note : this package is for private SSO Server with own standard. This might be different from SSO with international standards.
- we don't have a github repository for this package because we use it for our internal needs. Harefa : [email protected]