New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resource owner password credentials grant failing #158
Comments
Can you provide the error you're seeing? Also, in your example code, assuming you're using the actual client Id and client secret in the authorization header and the request body? For example, if
It looks like Axios defaults to the correct |
Yes all of the above are being sent as you have suggested already. I just replaced the actual ids in the code above. |
Can you confirm the correct |
Yes I have specifically set the content-type in the header has you requested, still got the same error. |
There must be something strange about how axios is encoding the request body. Your issue looks to be similar to this one. https://medium.com/@siwanyt/axios-x-www-form-urlencoded-issue-55de9564f8c0 |
Thanks @robotdan yes that was the issue I had to encode the data. I am however not getting refresh_token, only access_token. |
In order to receive a refresh token, you'll need to add the https://fusionauth.io/docs/v1/tech/oauth/endpoints#resource-owner-password-credentials-grant-request. |
Thanks @robotdan that solves it 👍🏼 |
Hi @Nosherwan can you please share me the sample code on how to get token using resource owner password credentials. |
@RameshAmzur the sample code is exactly as above with the only difference I encode the data before sending it via stringify function from a npm package called 'querystring'. import { stringify } from 'querystring';
const url = `${fusionAuthBaseUrl}/oauth2/token`;
const encodedSecret = Buffer.from('clientId:clientSecret').toString('base64')
return Axios({
method: 'POST',
url,
headers: {
Authorization: `Basic ${encodedSecret}`,
},
data: stringify({
client_id: 'client_id',
grant_type: 'password',
username: "my@email.com",
password: "password"
})
})
.catch((error: any) => {
console.log('FusionAuth userinfo call failed with error:', error)
}); |
Thank you @Nosherwan. But with this code we are getting 401 unauthorized error while validating the token.But the same class is working for validating Authorization code flow. Thank you. |
Resource owner password credentials grant failing
Description
I am trying to get tokens on behalf of a user by using
/oauth2/token
endpoint. However I receive different errors based on the following code in my web server app:I suspect there is some requirement for the call that I have missed.
The text was updated successfully, but these errors were encountered: