Support for Bearer / JWT Authentication
-
Hey,
I have JSON Web Tokens (JWT / Bearer Authentication) enabled on my site, and wanted to share how I managed to allow for this authentication method via your plugin.
I edited the swaggerauth.php file, and edited the
appendSwaggerAuth
function to include an additional method for an “apiKey” type (being that the plugin is based on OpenAPI 2.0) as follows:public function appendSwaggerAuth( $auth ) { if ( ! is_array( $auth ) ) { $auth = []; } $auth['basic'] = array( 'type' => 'basic' ); $auth['Bearer / JWT'] = array( 'type' => 'apiKey', 'name' => 'Authorization', 'in' => 'header' ); return $auth; }
And this enabled support for passing tokens for authentication, as well as basic auth:
Note that you need to prepend the token value with “Bearer”, ie: “Bearer <token>”, to get it to work properly.
However, after realizing basic auth wasn’t working when I had JWT enabled (without also passing a token with basic auth), I came up with an alternate solution to this, but figured I share this solution anyways should anyone else be looking to achieve something similar. ??
- The topic ‘Support for Bearer / JWT Authentication’ is closed to new replies.