mashery / iodocs

Interactive API documentation system
MIT License
1.89k stars 415 forks source link

Auth Key authentication header #207

Closed sofist-lucaskatayama closed 10 years ago

sofist-lucaskatayama commented 10 years ago

Hi In my app, I needed a X-Token header with the api key. So I made a change in your code to have this config

"auth" : {
    "key" : {
        "param" : "X-Token",
        "location" : "header"
    }
}

_app.js 939_

        if(checkObjVal(apiConfig,'auth','key','location').exists){
            location =  checkObjVal(apiConfig,'auth','key','location').value;
        }
        // Add API Key to params, if any.                                                                                                             
        if (apiKey != '' && apiKey != 'undefined' && apiKey != undefined) {
            if(location == 'header'){
                options.headers[apiConfig.auth.key.param] = apiKey;
            }
            else{
                if (options.path.indexOf('?') !== -1) {
                    options.path += '&';
                }
                else {
                    options.path += '?';
                }
                console.log(apiConfig.auth.key.param);
                options.path += apiConfig.auth.key.param + '=' + apiKey;
            }
        }

So if this is useful for you. Please make it permanent.

jlouthan commented 10 years ago

:+1: Thanks for posting this. Exactly what I needed.

trentster commented 9 years ago

Thanks for this - this is also exactly what I needed

phairow commented 9 years ago

looks like a version of this was just merged to master with PR 224 :)

https://github.com/mashery/iodocs/pull/224/files

sofist-lucaskatayama commented 9 years ago

Nice =) Tnx