-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Description
Right now this declaration is complex and there are some inconsistencies when declaring OAuth2 Grant flows.
For example, right now Implicit Grant looks like:
"implicit": {
"loginEndpoint": {
"url": "http://petstore.swagger.wordnik.com/oauth/dialog"
},
"tokenName": "access_token"
}and authorization code looks like:
"authorization_code": {
"tokenRequestEndpoint": {
"url": "http://petstore.swagger.wordnik.com/oauth/requestToken",
"clientIdName": "client_id",
"clientSecretName": "client_secret"
},
"tokenEndpoint": {
"url": "http://petstore.swagger.wordnik.com/oauth/token",
"tokenName": "auth_code"
}
}You can see that for the Implicit, the tokenName field as at the base of the object, and in the Authorization Code it's at the Token Endpoint object.
I wrote a post about the possible changes that can be done in the google group, so I'm copying it here directly:
Looking at the the spec - http://tools.ietf.org/html/rfc6749 - and based on those blog posts, it seems that the whole definition can be simplified.
There are two type of endpoints involved in the OAuth2 process - the Authorization Endpoint and the Token Endpoint (http://tools.ietf.org/html/rfc6749#section-3).
These two endpoints are used in the 4 different grant flows (http://tools.ietf.org/html/rfc6749#section-4), but they're not always used.
So we have this:
- Authorization Code Grant - uses both.
- Implicit Grant - Only the Authorization Endpoint is used.
- Resource Owner Password Credentials Grant - Only the Token Endpoint is used.
- Client Credentials Grant - Only the Token Endpoint is used.
As far as I can tell, you can basically support all grant flows with those two endpoints. The difference between them will be with the parameters sent to them, and those are completely controlled by the client performing the authorization.
Currently, the swagger specification officially supports only the first two grant flows, but as you can see, we can easily modify it to support all four.
I would suggest it looks like:
"authorizations" : {
"auth_name" : {
"type" : "oauth2",
"scopes" : ["scope1", "scope2", "..."],
"authorizationEndpoint" : "https://....",
"tokenEndpoint" : "https://....",
"grantFlows" : ["Authorization Code", "Implicit", "Resource Owner Password Credentials", "Client Credentials"]
}
}If the server uses different authorization and token endpoints for different grant flows, then they could just create a different "auth_name" per set.
It's a good idea to keep the "scopes" there as this is metadata the developers may need to develop the app. In fact, we may want to expand on each scope giving an additional description to them so that the developer knows which scope means what.
One important difference between that and the current implementation is that it does not include the "tokenName", "clientIdName" and "clientSecretName" parameters. As far as I understand, those are meant to allow some flexibility in deciding what these parameters can be called. However, if I've read the oauth2 spec correctly, they are always "access_token", "client_id" and "client_secret" (respectively). In other words, the oauth2 spec doesn't allow flexibility in the naming convention and as such, we don't need to allow that in the swagger spec as well.