--
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.
Actually you can write your own authentication piece to add the header. Look at the swagger.js project and see the ApiKeyAuthentication. You have everything available to generate a signature and sign the request with a header. Give it a shot and post back any questions.
Basically, what you want is to add another header parameter. This can be done either as a header parameter per operation or as an authorization scheme with a header-typed api key.As for 'make Swagger sign the request body' - that's not something Swagger does.
I assume that when you say Swagger here, you mean the UI, and just like any other client that you'd have to tell it to do so, so you would need to tell Swagger-UI to do it with changes to its code. This is definitely doable.
On 31 July 2014 08:46, j3d <aga...@gmail.com> wrote:
Hello,
Till now I've used a GUID as the API key and just compared the api_key header with the key provided via Swagger-ui... but now it is time to get serious so I'm implementing a private/public key mechanism where I'll provide two headers: one containing the public api_key (as before) and another one containging the HMAC signature generated by hashing the request body.
When the backend receives the requests, it uses the public API key (api_key header) to retrieve the secret key from the database and then hashes the body of the incoming request. If the resulting hash matches with the signature contained in the request headers, then the request is accepted, otherwise it is rejected.
The question is: how do I make Swagger sign the request body and put the calculated hash in the request headers?
Thanks,
j3d
--
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-swaggersocket+unsub...@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-swaggersocket+unsub...@googlegroups.com.
Actually you can write your own authentication piece to add the header. Look at the swagger.js project and see the ApiKeyAuthentication. You have everything available to generate a signature and sign the request with a header. Give it a shot and post back any questions.
Basically, what you want is to add another header parameter. This can be done either as a header parameter per operation or as an authorization scheme with a header-typed api key.As for 'make Swagger sign the request body' - that's not something Swagger does.
I assume that when you say Swagger here, you mean the UI, and just like any other client that you'd have to tell it to do so, so you would need to tell Swagger-UI to do it with changes to its code. This is definitely doable.
On 31 July 2014 08:46, j3d <aga...@gmail.com> wrote:
Hello,
Till now I've used a GUID as the API key and just compared the api_key header with the key provided via Swagger-ui... but now it is time to get serious so I'm implementing a private/public key mechanism where I'll provide two headers: one containing the public api_key (as before) and another one containging the HMAC signature generated by hashing the request body.
When the backend receives the requests, it uses the public API key (api_key header) to retrieve the secret key from the database and then hashes the body of the incoming request. If the resulting hash matches with the signature contained in the request headers, then the request is accepted, otherwise it is rejected.
The question is: how do I make Swagger sign the request body and put the calculated hash in the request headers?
Thanks,
j3d
--
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-swaggersocket+unsub...@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-swaggersocket+unsub...@googlegroups.com.
Yes, you don’t need to use coffeescript for this.
To make your own request signer, just make a class following this prototype:
var CustomRequestSigner = function(name) {
this.name = name;
};
CustomRequestSigner.prototype.apply = function(obj, authorizations) {
var hashFunction = this._btoa;
var hash = hashFunction(obj.url);
obj.headers["signature"] = hash;
return true;
};
This example takes the URL and simply computes the base 64 encoding of it—of course you’d use your own magic function. But once done, it will add a header called “signature” with that value.
To apply the function, simply add it when initializing swagger-ui or swagger.js:
window.authorizations.add(“specialSignature", new CustomRequestSigner(“specialSignature");and it’ll fire on any request against an operation with either NO authorizations specified on it (meaning, apply everything) or any operations that request that authorization explicitly:
implicit:
"apis": [
{
"path": "/pet/{petId}",
"operations": [
{
"method": "GET",explicit:
"apis": [
{
"path": "/pet/{petId}",
"operations": [
{
"method": "GET",
"authorizations": {
"specialSignature": {}
},To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.