| Start |
|---|
| OAuth 2 with Redis Implementation - grant_type: password In this example I will be using oauth2 in rest api with redis database **Important:** You will need to install redis database on your machine, Download it from [here](https://redis.io/download) for linux users and from [here](https://github.com/ServiceStack/redis-windows) to install windows version, and we will be using redis manager desktop app, install it from [here](https://redisdesktop.com/download). Now we have to set our node.js server to use redis database.
You only need to install redis on your machine and run the following node file Note: This file will set credentials for your frontend to request token So your request from Sample redis database after calling the above file:
Request will be as follows: Sample Call to api Header: a. clientId + secretId to base64 username: user that request token password: user password grant_type: depends on what options do you want, I choose passwod which takes only username and password to be created in redis, Data on redis will be as below: username: user that request token grant_type: depends on what options do you want, I choose passwod which takes only username and password to be created in redis, Data on redis will be as below: So We need to call our api and grab some secured data with our access token we have just created, see below: when token expires api will throw an error that the token expires and you cannot have access to any of the api calls, see image below : Lets see what to do if the token expires, Let me first explain it to you, if access token expires a refresh_token exists in redis that reference the expired access_token So what we need is to call oauth/token again with the refresh_token grant_type and set the authorization to the Basic clientId:clientsecret ( to base 64 ! ) and finally send the refresh_token, this will generate a new access_token with a new expiry data. The following picture shows how to get a new access token:
Hope to Help! |
Read Article
https://develop.horje.com/learn/1434/reference