- Linux Ubuntu 20.04
- Clone repo to local
git clone https://github.com/aniket-k-kaushik/authentication-and-authorization.git
rvm install 3.0.1
- Install Node 16.4.2
nvm install 16.4.2
- Install Postgres
sudo apt install postgresql-12 libpq-dev
- Create Username and password to access postgreSQL
sudo -u postgres createuser aniket -s // In place of aniket you can give your name
sudo -u postgres psql
To set password for the new user we just created
postgres=# \password aniket // aniket is the username
Then Enter possword and re-enter it to confirm it.
- Go to authentication-and-authorization/ds-assignment-backend
cd authentication-and-authorization/ds-assignment-backend
- Install gem
bundle install
- Install node packages
yarn install
- Setup ENV's
Open .env
-
Update
DATABASE_URL
in.env
as per localpsql
creds. For example, if the user isaniket
and password isaniket
, change the variable asDATABASE_URL="postgres://aniket:aniket@localhost/ds-assignment-backend?encoding=utf8&pool=5&timeout=5000"
-
Run
rake db:create
to create the database
rake db:create
- Run
rake db:migrate
for migrations
rake db:migrate
- Run
rake db:seed
for populating the database with initial data
rake db:seed
- Run
rails s
to run rails server
rails s
- Navigate to http://127.0.0.1:3000/
- It takes you to root page
The
Sign In and Sign Up
are basicdevise
session based authentions.
The {"name"=>"Web Client", "client_id"=>"NJkR6r9S5XlZyaqmWTwwWoZ4TM4j2dJssD5jkIZgIwY", "client_secret"=>"4hq0friqgrFaH0mxsY0szZHSbo2M-wLODIcGSxAXb7M"}
is used in API authentication
and authorization
- SignUp link take us to the
Sign Up
page
- SignIn link takes us to the
Sign In
page
- For this we would need an Postman APP
- In postman app, copy and paste the URL and Request should be
POST
- Go to
Header
Section of the postman app addContent-Type
application/json
- Go to
Body
selectraw
and paste the below lines
{
"email" : "[email protected]", // email you would like to register
"password" : "password", // password you would like to regiter
"client_id" : "NJkR6r9S5XlZyaqmWTwwWoZ4TM4j2dJssD5jkIZgIwY" // copy the client_id in the root page and replace it with the current string
}
- Copy the below link and page it in the postman
Enter Request URL
input box
http://127.0.0.1:3000/api/v1/users
- you can expect a similar kind of response
{
"id": 3,
"email": "[email protected]",
"access_token": "-9dZnzOYHrn2o1FWgaqw6RjTu5YcAMniNAcg3wy-6YI",
"token_type": "Bearer",
"expires_in": 7200,
"refresh_token": "496f3c806bfa1d2626cfddf8b67ab312e0a78b9b3ddaeecd70aa9e70d173d579",
"created_at": 1653948033
}
- In postman app, copy and paste the URL and Request should be
POST
- Go to
Header
Section of the postman app addContent-Type
application/json
- Go to
Body
selectraw
and paste the below lines
{
"grant_type" : "password",
"email" : "[email protected]",
"password" : "password",
"client_id" : "NJkR6r9S5XlZyaqmWTwwWoZ4TM4j2dJssD5jkIZgIwY",
"client_secret" : "4hq0friqgrFaH0mxsY0szZHSbo2M-wLODIcGSxAXb7M"
}
- Copy the below link and page it in the postman
Enter Request URL
input box
http://127.0.0.1:3000/api/v1/oauth/token
- you can expect a similar kind of response
{
"access_token": "tR3CriKQhT24e5JQ05kSaJxF1jnl3aCW43bFGnR-JJQ",
"token_type": "Bearer",
"expires_in": 7200,
"refresh_token": "t6FpPW-1Kw1p_kchsMwii1ruI_h6pHQI4x9MtJJYkaA",
"created_at": 1653948364
}
- In postman app, copy and paste the URL and Request should be
POST
- Go to
Header
Section of the postman app addContent-Type
application/json
- Go to
Body
selectraw
and paste the below lines
{
"token" : "UPML64iUotDeSjqLQBvTAuLB7DmVVla2TuGcg6Fb0Ek",
"client_id" : "NJkR6r9S5XlZyaqmWTwwWoZ4TM4j2dJssD5jkIZgIwY",
"client_secret" : "4hq0friqgrFaH0mxsY0szZHSbo2M-wLODIcGSxAXb7M"
}
- Copy the below link and page it in the postman
Enter Request URL
input box
http://127.0.0.1:3000/api/v1/oauth/revoke
- you can expect a similar kind of response
{}