README
Follow this for getting started
What is this module for?
this module is used for authentication and authorization
Who do I talk to?
NEW FEATUES I AM WORKING ON
- gmail authentication
How do I get set up?
npm install authkamodh
FEATURES AVAILABLE
signtoken('server secret', json data to encript into token, accesstokenexpiry in seconds, refreshtoken expiry)
**Examples:**
**signtoken ('server secret',{userid:1, role: 'user'} , 30000, 'unlimited')**
**signtoken ('server secret',{userid:1, role: 'user'} , 30000, 500000)**
**Explaination:**
**signtoken will generate the token and lock it with key 'server secret'**
authenticate('server secret')
**Explaination: will decrypt the token into json data by unlocking it with the key 'server secret'**
**otherwise throws error if token is expired or invalid**
authorize(role)
**Explaination: will authorize for the given role**
refreshtoken
**you have to pass accesstoken in header and refreshtoken in body**
**Explaination:**
**this will generate the new accesstoken from refreshtoken passed in body**
USAGE
const auth = ;
app
curl --request POST --url http://localhost:3000/login
// API with admin acccess onlyapp
curl --request POST
--url http://localhost:3000/adminurl
--header 'authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOjEsInJvbGUiOiJ1c2VyIiwiaWF0IjoxNTEzMzM5MTQ5LCJleHAiOjE1MTMzNjkxNDl9.FtNKnTvm5EcmMcEehcz47ll97DZnetPsNELIlxo-4y4'
// API with user access onlyapp
// API for user and admin accessapp
// Accessing the session user after auth and any user roleapp
//Getting new access and refresh token// NOTE make sure you pass the Authorization Header with accesstoken and in body send {refreshtoken: "<refresh token>"}app
curl --request POST
--url http://localhost:3000/refresh
--header 'authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOjEsInJvbGUiOiJ1c2VyIiwiaWF0IjoxNTEzMzM5MTQ5LCJleHAiOjE1MTMzNjkxNDl9.FtNKnTvm5EcmMcEehcz47ll97DZnetPsNELIlxo-4y4'
--header 'content-type: application/json'
--data '{"refreshtoken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiJleUpoYkdjaU9pSklVekkxTmlJc0luUjVjQ0k2SWtwWFZDSjkuZXlKMWMyVnlhV1FpT2pFc0luSnZiR1VpT2lKMWMyVnlJaXdpYVdGMElqb3hOVEV6TXpNNU1UUTVMQ0psZUhBaU9qRTFNVE16TmpreE5EbDkuRnROS25Udm01RWNtTWNFZWhjejQ3bGw5N0RabmV0UHNORUxJbHhvLTR5NCIsInZhbGlkIjpmYWxzZSwiaWF0IjoxNTEzMzM5MTQ5LCJleHAiOjE1MTQzNzU5NDl9.-Jc_irxnE-W87SBQYAW8fU6-xulGGLbGoiMS5zSk7nI"}'
SCREENSHOTS
login
Admin URL
Refresh TOKEN URL