Extensibility of security definitions?
I'm dealing with cases where there are a lot of extended or custom authentication systems around. Various Active Directory scenarios are the most egregious example.
In looking how to represent this in our swagger docs, the security scheme object seems pretty hard-wired to basic, api key, and oauth 2. Is there an intended way to add new authentication types to the document, even if the downstream consumers won't understand it directly? Or should I put:
"type": "basic",
"x-but-actually-it-is": "someCustomAuth"
or something along those lines? Is there a recommendation or pattern I can follow here?
For now, yes, you can use the vendor extensions to further extend the definitions. We realize it may not be optimal, but that's really one of the reasons we added them.
If you have suggestions as to how to make the security definitions more... flexible in the future, feel free to provide the feedback. Thanks.
My concern is that you can extend the existing definitions, but you can't create new ones. For example, if I have "type": "basic", naive clients will try to use basic authentication instead of the actual custom scheme.
Would adding 'custom' to the allowed values for the 'type' property work? That way we could mark something as 'custom', use extensions to supply whatever actual information is needed, and naive clients wouldn't try to use 'basic' or 'oauth2' or whatever?
Either that, or make the type property an open set that could be anything - so I could put for example "azure-active-directory" or something like that in the type property? If it's basic, apikey, or oauth2 then the rest of the spec applies as usual, but the other options are available. Kind of like the format property on primitive data types.
Right now it's not possible, and I don't know if it would make sense to allow it in the future. There are several feature requests regarding security definitions and we'll have to look into everything. The challenge with this regard is the tooling support. If we allow non-predefined schemes, it would be extremely difficult to support. On the other hand, it's obvious that we are unable to cover any definition possible out there. It's a matter of where we want to take the spec (just like any other feature request).
Regarding your comparison with the format field, I see a huge difference here as the type offers the basic constraints even if the format is unknown. Having any value for the security type offers no constraint if the type is unknown. Yes, we can offer extensibility with the tools, but that's easier said and done.
I was coming here to request support for Client JWT Bearer Assertions. A custom type could allow the same parameter definitions as any other request--after all, security credentials are just a predefined set of standard request parameters (query, body, headers).
Parent issue: #585
We have the same issue. Among several other auth schemes, our API supports JWT and we currently have no way to declare that. We also support Basic Auth and so are reluctant to advertise JWT as Basic also.
The original goal of the security definitions was to declare a fixed set of authorization types, so that any client consuming the spec can connect to it. Thus making a custom auth scheme wouldn't make sense, because no client would be able to authenticate against it without the matching custom logic.
That goal may be worth revisiting but it needs to be very deliberate. If a client can describe some custom auth scheme, there would be no way to connect to it in a general sense.
JWT makes sense as a standard, but there are many others as well, too many to implement all of.
Should that original design goal go away?
I have a similar issue. Our API utilizes the HTTP Signatures spec for authorization and I don't see a clean way to specify that as option. https://www.ietf.org/archive/id/draft-cavage-http-signatures-05.txt
I would suggest (a) continue expanding the fixed set to include internet standard protocols and (b) making a flexible scheme to support anything outside of that. The goal of a fixed set really will help move things forward, but if the fixed set doesn't include commonly used techniques (like JWT or HTTP signatures) it discourages those standard implementations.
Any news on it? Latest comment 5 may in this issue, still waiting support for JWT
+1
The security in the spec has been reworked to allow for such flexibility. Check it out!
@webron would you mind linking to the update on this?
Take a look at https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.md#securitySchemeObject.
It supports extensions in general. Also, basic has been changed to http and the scheme was added. If you end up using bearer, for example, you can use that to describe JWT tokens.
what about swagger 2.0 definitions? No way to follow same approach OpenAPI uses ?
Landed on this wondering how todescribe Hawk and other custom security definitions which don't fit the currently approved list of schemas and types in OAS3.