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

Created on 27 Apr 2016  路  11Comments  路  Source: Kong/kong

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

Most helpful comment

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

All 11 comments

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>

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

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

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>

fixed by #1359

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.

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=

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" ...

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

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

it works fine now. Thank you!

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marktopper picture marktopper  路  41Comments

jeremyxu2010 picture jeremyxu2010  路  39Comments

throrin19 picture throrin19  路  39Comments

sonicaghi picture sonicaghi  路  39Comments

jason-riddle picture jason-riddle  路  40Comments