request access token from keycloak using restapi

A few days ago, I was assigned a task to write a script to request access token from keycloak using restapi. After googling in the internet, I got the answer. Mark it here for later reference:

curl -L -X POST ‘http://10.10.10.10:9090/auth/realms/subprov/protocol/openid-connect/token’ \
-H ‘Content-Type: application/x-www-form-urlencoded’ \
–data-urlencode ‘client_id=demo-client-id’ \
–data-urlencode ‘client_secret=demo-clent-secret’ \
–data-urlencode ‘grant_type=password’ \
–data-urlencode ‘scope=openid’ \
–data-urlencode ‘username=demo-user’ \
–data-urlencode ‘password=demo-password’\

the command arguments can be replaced accordingly.