swagger-js icon indicating copy to clipboard operation
swagger-js copied to clipboard

BasicAuth Header

Open SebiGo opened this issue 10 years ago • 3 comments

Adding the Authorization Header (or any other security header) seems broken in v2.1.13 (and other versions). This is what I do:

var client = new SwaggerClient({
    url: myUrl,
    success: function () {
        client.someMethod();
    },
    authorizations : {
        easyapi_basic: new SwaggerClient.PasswordAuthorization('user', 'pass'),
    },
});

There is a proper "Authorization:Basic dXNlcjpwYXNz" in the header when retrieving myUrl. Later, when when calling the someMethod() there is no "Authorization:" header present.

SebiGo avatar Mar 30 '16 15:03 SebiGo

If your definition doesn't declare that it's required, then it won't be sent. Try adding the security attribute on the operation, and making sure the reference has the same name as easyapi_basic. For example: http://petstore.swagger.io/v2/swagger.json

fehguy avatar Mar 30 '16 15:03 fehguy

Thats it, thanks. I wasn't aware that "easyapi_basic" is a reference to the securityDefinitions.

SebiGo avatar Mar 30 '16 15:03 SebiGo

great

fehguy avatar Mar 30 '16 15:03 fehguy