How to make a username password request with auth0 custom api, getting error “unsupported grant type: password” error

随声附和 提交于 2019-11-30 16:44:27

问题


I tried using the auth0 postman template to make an authentication request using username and password and I'm getting an unsupported grant type: password error. What am I doing wrong?

var client = new RestClient("https://test.auth0.com/oauth/token");
var request = new RestRequest(Method.POST);
request.AddHeader("postman-token", "abc");
request.AddHeader("cache-control", "no-cache");
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("application/x-www-form-urlencoded", "grant_type=password&client_id=foo&audience=&username=test&password=test&scope=openid%20email%20picture%20nickname", ParameterType.RequestBody);

回答1:


  1. Log into the Auth0 dashboard
  2. Go to account settings (top right under your username)
  3. On the general tab scroll down to the API Authorization Settings section
  4. Default Audience would be your API identifier (if you have an API)
  5. Default Directory would be your connection such as database connection name

In your POST to oauth/token do not include audience (if you specified the default above).

Gotta love how Auth0 makes authentication easy and painfully hard at the same time.

Refer below screenshot as a reference.




回答2:


These are the exact steps I have taken in order to resolve this exact issue

Login with browser on desktop At top right of UI, click click username, Settings

Scroll down to API Authorization Settings

Enter valid values in BOTH Default Audience, and Default Directory.

For example, for me I already had been using the Lock screen, and had already setup a Default Audience which I was setting in my client application and everything was working.

I also had already setup a Connections > Database, with the name of Username-Password-Authentication.

Here is a screenshot of it working after doing the above, using the postman collection , which at the time of writing, is contained here

https://app.getpostman.com/run-collection/2a9bc47495ab00cda178

which is referenced here

https://auth0.com/docs/api/authentication#code-samples




回答3:


Go to Default App > Settings >

In the bottom of settings, Click {Show Advanced Settings}

Select Grant Types Tab

Check the password which is unchecked by default

Post request to *//oauth/token and it works



来源:https://stackoverflow.com/questions/41626602/how-to-make-a-username-password-request-with-auth0-custom-api-getting-error-un

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!