Okta API- Resource owner password flow /token

nodejs

#1

Hi, I am trying to implement username password login on the defualt authorization server and get a token with /token endpoint. however i get this Error :
Bad request. Accept and/or Content-Type headers likely do not match supported values.

I am setting Accept header to application/json and content-type to application/x-www-form-urlencoded

this is the guide I was following:
https://developer.okta.com/authentication-guide/implementing-authentication/password

My node.js code is here

axios.defaults.headers.common[‘authorization’] =
‘Basic ‘+ Buffer.from(provider.clientId+’:’+provider.clientSecret).toString(‘base64’);
axios.defaults.headers.common[‘accept’] = ‘application/json’;
axios.defaults.headers.common[‘content-type’] = ‘application/x-www-form-urlencoded’;

let body = {
  grant_type:'password',

  username: username,

  password: password,

  scope: 'openid profile email'
}

axios.post(host+'/oauth2/default/v1/token',body)

Any help would be appreciated, thanks :slight_smile:


#2

Hi @ahmed,

Have you tried using curl or postman to make the request?
I have tested this flow using the postman collection and it works fine.

Try the curl request in this link and check if that works - https://developer.okta.com/authentication-guide/implementing-authentication/password#2-using-the-resource-owner-password-flow


#3

The problem was with the body as its a javascript object, when i turned it to a string and added the params to it like a form it worked


#4

Hey @ahmed, I’m curious what your use case is. Why do you want to use the resource owner password grant here? Are you building a totally customized login form?


#5

yes, I am building a custom form , where the credentials pass by my server before going to okta


#6

Hey folks, I am new to Okta, having the same error here. But my case is using content-type:application/json, instead of x-www-form-urlencoded

Is Okta not supporting application/json at the moment ? Thanks in advance!


#7

Hey @wayne! Can you post a new topic with some more details of what you are trying to do and the problem you are running into?


#8

@nate.barbettini

thanks for the reply, I created a new one here: