How to access request body parameters in addApiKeyAuthorization() function?

77 views
Skip to first unread message

Marta Doberschuetz

unread,
May 28, 2015, 6:26:22 AM5/28/15
to swagger-sw...@googlegroups.com
I want to send a request to my ASP.NET WebApi2 application from Swagger UI. I need to add Authorization headers to the request. I have added my custom index.html file and modified the addApiKeyAuthorization() function to be able to send Authorization header with every request. The function looks like that:

function addApiKeyAuthorization() {
        var key = encodeURIComponent($('#input_apiKey')[0].value);
        if (key && key.trim() != "") {
            var value = "auth-scheme customer_id=123456,order_id=56789,signature=hhhhjjjjkkkklllllll";
            var authKeyHeader = new SwaggerClient.ApiKeyAuthorization("Authorization", value, "header");
            window.swaggerUi.api.clientAuthorizations.add("Authorization", authKeyHeader);
        }
    }

At the moment the signature is hardcoded (I know exactly what parameter values to pass in in the request body for the signature to be valid).

In order to generate a signature dynamically for given parameters in the request body I need to use  those parameters that are passed in in the request body. How can I access those parameters inside the addApiKeyAuthorization() function so that I could set the signature parameter in the Authorization header dynamically? 

Josh Ponelat

unread,
May 28, 2015, 7:22:53 AM5/28/15
to swagger-sw...@googlegroups.com
To do so you can pass in a function instead of a ApiKeyAuthorization, take a look at this gist to get you going...

https://gist.github.com/ponelat/05c775d06397b24811a4

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marta Doberschuetz

unread,
Jun 4, 2015, 6:44:24 AM6/4/15
to swagger-sw...@googlegroups.com
That helped, thanks. I was able to access the headers and modify the signature.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.

Josh Ponelat

unread,
Jun 4, 2015, 7:21:42 AM6/4/15
to swagger-sw...@googlegroups.com
Glad to hear it :D

To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages