I am working with the Strava API and I have the following question. If I try from Postman with my client_secret and with the corresponding code it works for me
But this, taken to Angular, I'm going crazy to make it work, right now I have this, and it gives me all the time bad Request, without more information.
Let's see if you can give me a hand to launch the request, because, I think, I'm putting those params wrong (the ones you see in Postman)
const headers = new HttpHeaders()
const body = JSON.stringify({})
const params = new HttpParams()
.set('client_id', environment.client_id)
.set('client_secret', environment.client_secret)
.set('code', code)
.set('grant_type', environment.grant_type)
this.http
.post<any>('https://www.strava.com/oauth/token', body, {
headers: headers,
params: params
})
.pipe(catchError(this.formatErrors))
.subscribe((res) => console.log(res))
EDITED
I have added the .append, as you mention and I still get the same error.
const headers = new HttpHeaders()
const body = JSON.stringify({})
const params = new HttpParams()
.append('client_id', environment.client_id)
.append('client_secret', environment.client_secret)
.append('code', code)
.append('grant_type', environment.grant_type)
this.http
.post<any>('https://www.strava.com/oauth/token', body, {
headers: headers,
params: params
})
// .pipe(catchError(this.formatErrors))
.subscribe((res) => console.log(res))
And the error it gives is the following:
EDIT 2
I have continued working, I have created an injector to control the errors, but I am going crazy, I do not understand why it works from Postman and not from Angular
I enclose the capture of the errors and how the headers and the body are formatted before launching the request. It annoys me that they are not of type Key - Value and that they are Key - Array. I don't know if this is normal
On the other hand I attach the new code to see if you see something strange
refreshToken(code: string){
const headers = new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded'
})
const body = new HttpParams({
fromObject : {
client_id: environment.client_id,
client_secret: environment.client_secret,
code: code,
grant_type: environment.grant_type
}
})
this.http
.post<any>('https://www.strava.com/oauth/token', body, {
headers: headers
//params: params
})
.subscribe((res) => console.log(res))
}
In case it served to clarify something, I leave here the direct link to the documentation , but I see everything correct
In the end, the problem with everything was the routes file, the routes were not configured correctly, therefore, as he exits the application and re-enters, for Strava's OAUTH2 authentication, he went crazy here.
To fix this, I have left the routes as follows
Really, I was missing the nodes
path: ''
andpath: '**'
Regarding the code that we have been seeing these days, it has been as follows.