Best way to set api key dynamically
Hi, all. I've got a Swagger spec file that I'd like to use with the Try It Out function in SwaggerUI. We're hosting SwaggerUI on our site in a section of the site that requires authorization, so users have already entered name & password once. I'd like them to be able to use Try It Out without authenticating again and I'd like to do it without actually writing the API key data into the Swagger JSON file itself. Does anyone have a recommendation on the best way to do this?
I've tried:
1. Adding a spec parameter to the code below and writing the Swagger info to it
2. Setting request.curlOptions and adding a header value for the api key
3. Adding the line requestInterceptor: (req) => { req.headers.append('apikey', 'apikeyvalue'); return req; },
but none of those worked for me.
Thanks very much.
window.onload = function() {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: '@Model.SwaggerFilename',
dom_id: '#swagger-ui',
deepLinking: true,
request.curlOptions: '[ -H "apikey: abcd"]',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
});
window.onload = function() {
// Begin Swagger UI call region
const ui = SwaggerUIBundle({
url: '@Model.SwaggerFilename',
dom_id: '#swagger-ui',
deepLinking: true,
request.curlOptions: '[ -H "apikey: abcd"]',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
});