Skip to content

Swagger/Swashbuckle OAuth2 Authorizations not set #1134

@danutzplusplus

Description

@danutzplusplus

I've found an issue and I'm not sure where it stems from. The point where it fails in inside a Swagger js library (swagger-ui-js), but it might either because of a misconfiguration in Swashbuckle, or an actual bug in Swagger (version: v2.1.0-M2).

The issue I found was after upgrading Swashbuckle from 4.x to 5 (in 4.x it worked without a hitch), and it manifests in the following way:
I've a couple of WebAPI services exposed using Swashbuckle, and I've configured them (just the same as I've configured 4.x) to use a local OAuth2 token issuer. I hit the [On/Off] button on a particular service, and start the OAuth2 requests, finalizing with the access_token stored locally in swagger (the [On/Off] button is [On], meaning authentication succeeded).

When I attempt to perform the actual call to the WebAPI service, it breaks locally in the javascript code, in swagger-ui-js, at line nr 900, at the point where it tries to call apply(obj, authorizations) on the reference retrieved from this.authz["oauth2"]

result = value.apply(obj, authorizations); // it breaks here because value is an empty js object, and apply is undefined

I've uploaded a screenshot of the firefox debugger: http://oi61.tinypic.com/2q1wk6e.jpg

I've traced where this.authz[key] is set, and its in the
SwaggerAuthorizations.prototype.add = function (name, auth) {
this.authz[name] = auth;

return auth;
};

I've then traced it, at least I hope I traced it correctly, to:
window.swaggerUi.api.clientAuthorizations.add.apply(window.swaggerUi.api.clientAuthorizations, arguments);
and I noticed arguments is an array, and the "oauth2" key has an empty js object, but I've not been able to find out where that arguments object is populated from.

Anyone else had this issue? Could this be just because of a misconfiguration server-side on my part? I would imagine if this was the case, the OAuth2 flow would break a lot sooner than when trying to perform the actual request with the received bearer token.

Thanks, and I hope someone is able to shed some light on this, and I'm stumped.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions