This repository has been archived by the owner on Sep 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 586
JWT security and scopes - my working solution #481
Comments
Great solution, thanks for sharing Riccardo! |
Only problem is it can't be documented through swagger-ui... |
We also came up with a similar solution. On top of that, we have added a version check to expire any existing tokens, when needed, to force a re-authentication.
|
@ric79 Thanks for the great post. What if you have a multiple security definition? securityDefinitions:
APIKey1:
description: "Accesso tramite JWT"
type: "apiKey"
name: "Authorization"
in: "header"
APIKey2:
description: "another key"
type: "apiKey"
name: "another key"
in: header
...
paths:
/protected_calls:
get:
security:
- APIKey: []
APIKey2: [] # Here, the endpoint uses both keys
x-security-scopes:
- admin
... And your authentication mw uses both keys? What do you use instead of ??? ? app.use(middleware.swaggerSecurity({
???: function(req, def, JWTAuth, callback) {
.... |
Did someone use this solution using Python and the Connexion module? |
Something like this?
const { authorize, authorizeAdmin } = require('./api/helpers/auth'); app.use(middleware.swaggerSecurity({
userKey: authorize,
adminKey: authorizeAdmin,
})); |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hello,
here there is my solution, hope I can help other developers!
Token
Lets us imagine that the APP will receive in the header a JWT token (TOKENVALUE). The token has been sign with a private key. Payload can be for example:
In my case, the scope is just an array of roles
Swagger.yaml
I have extended swagger adding x-security-scopes. This is the key point of the solution.
Client authorization
Every calls to server should contains
Middleware
In the swaggerSecurity function it is now easy to verify the token using the public key and check if there is an intersection between scopes from token and x-security-scopes
I'm a newbie to nodejs so just get the idea and not the specific implementation
Riccardo
The text was updated successfully, but these errors were encountered: