WSO2 Identity server supports all grant types those are defined in oAuth2 core specification
Four grant types:
- Authorization Code Grant
- Implicit Grant
- Resource Owner Password Credentials Grant (password)
- Client Credentials Grant
3. Get access token using password grant type
curl -k -d "grant_type=password&username=admin&password=admin" -H "Authorization: Basic ME5fbXdWRXpTVnhfalJIbDV2cmc4RHIycHZBYTp0RmZjcHVFRFM5V1d2eFFEc1ZCd0tWVGd0dE1h, Content-Type: application/x-www-form-urlencoded" https://localhost:9443/oauth2/token
ME5fbXdWRXpTVnhfalJIbDV2cmc4RHIycHZBYTp0RmZjcHVFRFM5V1d2eFFEc1ZCd0tWVGd is the encoded value of 0N_mwVEzSVx_jRHl5vrg8Dr2pvAa:tFfcpuEDS9WWvxQDsVBwKVTgttMa (<client_id>:<client_secret>). these value should be separated by colon(:).
https://localhost:9443/oauth2/token is the token endpoint url.
If you use <client_id>:<client_secret> without encoding, you can use below curl command to retrieve access token.
curl --user 0N_mwVEzSVx_jRHl5vrg8Dr2pvAa:tFfcpuEDS9WWvxQDsVBwKVTgttMa -k -d "grant_type=password&username=admin&password=admin" -H "Content-Type:application/x-www-form-urlencoded" https://localhost:9443/oauth2/token
When you request the access token, you will get this type of response.
{"token_type":"bearer","expires_in":3080,"refresh_token":"eaa3683b1cf78496b6c1e5b7ffc882","access_token":"3812fa8e788d67e89d604b509c943921"}
4. Client Credentials Grant
This grant type is more suitable to communicate between trusted parties. User credentials does not include in the request.
curl -u <client id>:<client secret> -k -d "grant_type=client_credentials" -H "Content-Type:application/x-www-form-urlencoded" https://localhost:9443/oauth2/token
I tried below curl command
curl -u qeqguSOG1OoDEz62PUedXOAftKsa:RRxJK1Rc49KM8gT71YSVYnwoR4Ea -k -d "grant_type=client_credentials" -H "Content-Type:application/x-www-form-urlencoded" https://localhost:9443/oauth2/token
I got below response.
{"token_type":"bearer","expires_in":3299,"access_token":"ff88f47bc137b4fd5eef5152b292e3ca"}
I will continue this blog post by explaining other grant types to get access token using curl commands in future.
Comments
Post a Comment