Thursday, January 31, 2019

Configure gmail to use as Email in Keycloak Realm

Keycloak allows us to use my built-in user related features, such as User registration, login etc.
Some of those need an email, such as verify email, forget password etc. Here I with share how to configure a Gmail as your email in Keycloak realm.
(If you want described explanation please read https://www.keycloak.org/docs/latest/server_admin/index.html#_email )

Goto Email on your Realm Setting.

Use Below common configurations.

  • Host: smtp.gmail.com
  • Port: 465
Now you have to Give your email to 


  • From
  • Username

And Password to the relevant field

Look Below image.


After that Please remember to click the Save button. Then click Test Connection to check whether the email is working properly. You can see a test email from keycloak in the Email inbox.

Thursday, January 24, 2019

How to configure Postman to get Access Tokens (OAuth 2.0) from Keycloak

First of all login to keycloak with admin account you initially created.
If you are not familiar use below link (https://www.keycloak.org/docs/latest/getting_started/index.html#creating-a-realm-and-user)

Now you have logged into Keycloak master realm as admin. Now let’s create Keycloak realm first. For that click on Left upper corner like the image below (For the first time it should only have the master realm since I did this before you can see my previous realms)



Click Add realm and give a proper name here I give kitcut-realm
Check the image below.



Now we need to create a client for our realm. Click on Client on Left sidebar on Next window.


Click Create button on the right side of the window. And give client name. Let say kitcut-app-client


Now Click Save button on the below.
On next window Scroll down to Access Type select Confidential


After that scroll down further more and you have to give least one * Valid Redirect URIs
Let say our redirect is http://localhost:3000/* now click Save on Bottom of page.

After that, you can see new Tab named Credentials appears next to the Settings tab on Top.


Select Client Id and Secret from the drop down named Client Authenticator.
Now we need to create a user to access the realm.
Click Users on the left sidebar and create a user. Let say admin-user.


Then click Save. On next window click Credentials on the top menu and give a password.
Here I will give password as the password. Please Click Temporary as Below.
(Otherwise keycloak will prompt to change the password on the first login)


Then click Reset Password to change the password.
Now completed to basic requirements to connect Postman to connect with keycloak.

We need few details to connect with keycloak.

Access Token URL: http://localhost:8180/auth/realms/kitcut-realm/protocol/openid-connect/token

Please note that your realm name should replace kitcut-realm in above URL

Username: admin-user
Password: password

Now we need client id and client secret.
For that go to Clients -> kitcut-app-client (Or whatever name you gave) -> Credentials

You will see an image like below


Your
Client ID: kitcut-app-client
Client Secret: 881cbb23-be8f-4f22-807c-5ec9d37f0653 (Add your one from above window)

Now Open Postman and Click Authorization button
Then Click Get New Access Token from below window.


You will see Below window.
Give a name to Token Name and Password Credentials on Grant Type drop down.
Give openid to Scope. Also above we collected details


Click Request Token button. If everything right you will see an image similar to below


Now press Use Token button. Well, now you have successfully added authorization header to Postman request.

Sunday, December 2, 2018

Beginners Guide To Install Postgres Ubuntu.

Nowadays most applications use PostgreSQL as their database than Mysql. PostgreSQL has earned a strong reputation for its proven architecture, reliability, data integrity, robust feature set, extensibility, and the dedication of the open source community behind the software to consistently deliver performant and innovative solutions. Therefore if you are planning to have a career in Software Engineering knowledge of PostgreSQL comes in handy. So today lets discuss Install Postgres Ubuntu. Reason for this post is there are few thing beginners should know when he starts using Postgres.
The easiest way to install Postgres in Ubuntu is run below command.
sudo apt install postgresql
This will install the latest PostgreSQL version which is currently postgresql-10.
But sometimes you might need an older version which compatible with your application.
For such an event you can use below procedure to achieve that.
For the tutorial, let’s install postgresql-9.6 for that run below commands in terminal.
sudo add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -sc)-pgdg main"
 
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
 
sudo apt-get update
 
sudo apt-get install postgresql-9.6


Now you have installed Postgres in Ubuntu and you can confirm the version using below command.
psql -V

If you can see a version number you installed, then Postgres successfully installed.
Now, let’s start Postgres using below command.

sudo service postgresql start


Now your server should be running. You can check that using below command.
sudo service postgresql status

Now how to access the psql using terminal?
When Postgres is being installed, it creates a user called postgres.This user is created as Ubuntu System user not in Postgres as Mysql would do. You can see it using the below command.
cat /etc/passwd

In end of file you can see a line starts with postgres. The x after postgres means there is no password setted for it.
Reason for bring this user matter is You need to log into psql using that user. this user is not activated and you should not activate is using passwd command. Otherwise it will leave security vulnerbility if you used weak password like postgres
Let's see how to use psql without activating postgres user.

Type below command to become postgres user without password. (For this you need root privilages)

sudo -i -u postgres


now type psql to enter Postgres terminal. After that type below command to change default user password.

\password postgres


Please remember that password. because it is needed when you are going to connect the Postgres through your application. If you want to exit terminal, then type \q and enter. Now you are in terminal as postgres user. use exit to log out. If you want to access psql terminal use below commad.
sudo -u postgres psql

If you don't want to use psql terminal you can use GUI client call pgamin
(https://www.pgadmin.org/download/) Now you you know basics of Install Postgres Ubuntu and get development start up :D