I am trying to get an authorization token from the refresh token authorization call with Home Connect. Apparently the following code is correct (I am not sure though, sorry) but I always get “400 (Bad Request)”, although from Postman the code works well, provided that you take into account to avoid some characters substitution, as pointed below (sorry for the bad formatting I do not know how to better paste it).
function HttpRefreshToken() {
//var TokenResult = http.post('https://api.home-connect.com/security/oauth/token?grant_type=refresh_token&refresh_token="' + refreshToken + '"&client_secret=' + clientSecret);
var baseUrl = "https://api.home-connect.com/security/oauth/token";
var httpHeaders = {
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
};
var body = '{"data": {"grant_type": "refresh_token", "refresh_token": "' + refreshToken + '", "client_secret": "' + clientSecret + '"}}';
var TokenResult = http.post(baseUrl, body, httpHeaders);
if (!TokenResult.data.error) {
return TokenResult.data.access_token;
} else {
return null;
}
}
The first commented line does not work so I tried the last command with parameters…
According to technical support:
"Body params will be the best choice. Code obviously handle some information encoded with base64 and need to be decoded on the backend. Some browsers intend to change some symbols to others in http urls. Correct base64 encoded information can contain following symbols:
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=
"
Is there a way to modify the code to make it work? Many thanks!, and sorry for my lack of knowledge ;-(