Skip to content
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

key-auth plugin error when creating new keys - "unsupported media type" - change of behavior #1182

Closed
sinfloodmusic opened this issue Apr 27, 2016 · 11 comments
Assignees

Comments

@sinfloodmusic
Copy link

sinfloodmusic commented Apr 27, 2016

Hi, recently upgraded to 0.8.0 and the behavior for the key-auth key creation on a consumer appears to have changed. The documentation (and previous behavior) asks for the following command to generate an apikey for a user:

curl -X POST http://localhost:8001/consumers/{consumer}/key-auth

This worked on the previous version I was running (0.7.0?) but now that command returns the following:

<html>
<head><title>415 Unsupported Media Type</title></head>
<body bgcolor="white">
<center><h1>415 Unsupported Media Type</h1></center>
<hr><center>openresty/1.9.7.3</center>
</body>
</html>

I found if I add an empty POST body it happily generates the key in the same way it used to.

curl -X POST http://localhost:8001/consumers/{consumer}/key-auth -d ""

Not sure if this is intentional and the plugin documentation is now lagging behind, or if this has cropped up since the update to 0.8.0. If it matters I'm running this on postgres.

Thanks!

Matt

@gavinzhou
Copy link

I get same error with jwt

curl -X POST http://127.0.0.1:8001/consumers/test02/jwt
<html>
<head><title>415 Unsupported Media Type</title></head>
<body bgcolor="white">
<center><h1>415 Unsupported Media Type</h1></center>
<hr><center>openresty/1.9.7.3</center>
</body>
</html>

@bhurlow
Copy link

bhurlow commented May 2, 2016

I'm also encountering this behavior on v0.8.1. Supplying an empty post body creates the proper keys

@mdan1eli
Copy link

or specifying the content type as "application/x-www-form-urlencoded" works as well

@jixiaod
Copy link

jixiaod commented Jul 19, 2016

I get same error with jwt

[root@v5 ~]# curl -X POST http://localhost:8001/consumers/Jason/jwt
<html>
<head><title>415 Unsupported Media Type</title></head>
<body bgcolor="white">
<center><h1>415 Unsupported Media Type</h1></center>
<hr><center>openresty/1.9.7.5</center>
</body>
</html>

@Tieske Tieske added this to the 0.9 milestone Jul 19, 2016
@Tieske
Copy link
Member

Tieske commented Jul 19, 2016

fixed by #1359

@Tieske Tieske closed this as completed Jul 19, 2016
@codeocelot
Copy link

Thanks @jixiaod Came here after encountering the issue following the jwt plugin docs. It may help others if that page is updated with the solution mentioned here.

@rootvar
Copy link

rootvar commented Jan 5, 2017

Still getting this error in key-auth.

Kong version 0.9.5

curl -X POST http://localhost:8001/consumers/d2ae1ba4-3922-4dd8-820a-e2346986ec92/key-auth 415 Unsupported Media Type

but works if I add -d flag:
curl -X POST http://localhost:8001/consumers/d2ae1ba4-3922-4dd8-820a-e2346986ec92/key-auth -d ""

Same error when using http on OS X:

http POST :8001/consumers/d2ae1ba4-3922-4dd8-820a-e2346986ec92/key-auth 415 Unsupported Media Type

But works if I pass empty 'key' in body:
http POST :8001/consumers/d2ae1ba4-3922-4dd8-820a-e2346986ec92/key-auth key=

@somebehemoth
Copy link

somebehemoth commented Jan 9, 2017

I am getting this with Kong 0.9.7 on OS X using curl. @mdan1eli suggested specifying Content-Type header and that worked for me. I too came here after having trouble with the JWT documentation.

curl -X POST -H "Content-Type: application/x-www-form-urlencoded" ...

@Tieske Tieske reopened this Jan 10, 2017
@Tieske
Copy link
Member

Tieske commented Jan 10, 2017

I had a look at what should be accepted, and came up with the following;

  • for PUT, POST, PATCH:

    • accept: content-type urlencoded, with proper body, or empty body
    • accept: content-type json, with proper body, or empty body
    • accept: no content-type provided, empty body
    • reject: everything else
  • for all other http methods: ignore the body and content-type header

@Tieske Tieske modified the milestones: 0.10 RC, 0.9 Jan 10, 2017
@Tieske Tieske self-assigned this Jan 10, 2017
@rootvar
Copy link

rootvar commented Jan 20, 2017

Updated to 0.9.7 and passing a blank object to body:
method: 'POST', body: {}, json: true

it works fine now. Thank you!

@thibaultcha
Copy link
Member

This has been fixed in #3077! It will be part of the 0.12 release :) Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests