I have keycloak standalone running on my local machine.
I created new realm called \'spring-test\', then new client called \'login-app\'
According to the rest docu
For those who landed here from a search looking for JavaScript
solution.
Here is an example when exchanging code
for access_token
with keycloak
authority using axios
.
querystring is used in this example:
npm install querystring
or
yarn add querystring
Sending the request:
import queryString from 'querystring'
const params = {
grant_type: 'authorization_code,
client_id: 'client-id-here',
code: 'code-from-previous-redirect',
redirect_uri: location.protocol + '//' + location.host
};
axios({
method: 'post',
url: 'https://my-keycloak.authority/token',
data: queryString.stringify(params),
config: {
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}
}).then(response => {
console.log(response.data);
}).catch(error => {
console.error(error);
});
You are required to send a POST request with the parameters as a URL encoded string in the request body.
FormData object does not work.