Skip to content

Commit

Permalink
Modify Swagger UI on the fly
Browse files Browse the repository at this point in the history
  • Loading branch information
Jozef Volak committed Feb 10, 2022
1 parent 4ecc7fa commit 05bb1d7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 54 deletions.
16 changes: 16 additions & 0 deletions config/krakend/scripts/wp_azure_swagger.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function swagger_auth_modal(r,jwt,scope,client_id)
local body = r:body()
if jwt == "true" then
-- change token request to id_token
body = body:gsub("response_type=token", "response_type=id_token");
-- -- -- disable client_id input box and use default
body = body:gsub("||A===x", "");
body = body:gsub('client_id="%+encodeURIComponent%(p%)', 'client_id=' .. client_id .. '"');
-- -- -- -- disable scopes selection and use default, add nonce query parameter
body = body:gsub('O=o.get%("allowedScopes"%)||o.get%("scopes"%),', "");
body = body:gsub('T%(%)%(c%)%?m%=c:F.a.List.isList%(c%)&&%(m=c.toArray%(%)%),m.length%>0', "true");
body = body:gsub('scope="%+encodeURIComponent%(m.join%(v%)%)', 'scope=' .. scope .. '&nonce=678910"');
r:headers('Content-Length', tostring(body:len()))
end
return body
end
20 changes: 19 additions & 1 deletion config/krakend/settings/workflow_proxy_docs_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,31 @@
{
"endpoint": "/api/uniflow/swagger-ui-bundle.js",
"method": "GET",
"url_pattern": "/docs/swagger-ui-bundle.js"
"url_pattern": "/docs/swagger-ui-bundle.js",
"extra_config": {
"github.com/devopsfaith/krakend-lua/proxy": {
"sources": ["scripts/wp_azure_swagger.lua"],
"allow_open_libs": true,
"post": "local r = response.load(); r:body(swagger_auth_modal(r, os.getenv('JWT_PRODUCTION'), 'openid', os.getenv('AZURE_KRAKEND_PLUGIN_CLIENT_ID')));",
"live": true
}
}
},
{
"endpoint": "/api/uniflow/swagger-ui.css.map",
"method": "GET",
"url_pattern": "/docs/swagger-ui.css.map"
},
{
"endpoint": "/api/uniflow/swagger-ui-standalone-preset.js",
"method": "GET",
"url_pattern": "/docs/swagger-ui-standalone-preset.js"
},
{
"endpoint": "/api/uniflow/swagger-ui-standalone-preset.js.map",
"method": "GET",
"url_pattern": "/docs/swagger-ui-standalone-preset.js.map"
},
{
"endpoint": "/api/uniflow/swagger-ui-init.js",
"method": "GET",
Expand Down
58 changes: 5 additions & 53 deletions config/krakend/templates/workflow_proxy_docs.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
],
{{end}}


{{ if .extra_config }}
"extra_config": {{ marshal .extra_config }},
{{end}}

"backend": [
{
"url_pattern": "{{ .url_pattern }}",
Expand Down Expand Up @@ -42,55 +45,4 @@
}
]
}
{{end}},
{
"endpoint": "/api/uniflow/docs/token",
"method": "POST",
"output_encoding": "no-op",
"headers_to_pass": ["*"],
"querystring_params":[
"*"
],
"backend": [
{
"url_pattern": "/{{ env "AZURE_TENANT_NAME"}}/oauth2/v2.0/token",
"encoding": "no-op",
"sd": "static",
"disable_host_sanitize": false,
"extra_config": {
"github.com/devopsfaith/krakend-martian": {
"fifo.Group": {
"scope": ["request", "response"],
"aggregateErrors": true,
"modifiers": [
{
"header.Modifier": {
"scope": ["request"],
"name": "Accept-Encoding",
"value": "identity"
}
},
{
"header.Modifier": {
"scope": ["request","response"],
"name": "Access-Control-Allow-Origin",
"value": "*"
}
},
{
"header.Modifier": {
"scope": ["request", "response"],
"name": "Access-Control-Allow-Headers",
"value": "X-Requested-With"
}
}
]
}
}
},
"host": [
"{{ env "AZURE_LOGIN_URL"}}"
]
}
]
}
{{end}}

0 comments on commit 05bb1d7

Please sign in to comment.