Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds ability to set oauth2RedirectUrl using env vars for Docker #3280

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,29 @@ docker run -p 80:8080 swaggerapi/swagger-ui

Will start nginx with swagger-ui on port 80.

When starting, the Docker container runs `docker-run.sh`, which gives you the ability to swap out variables set in the constructor of `SwaggerUIBundle` `index.html` with environment variables. Available variables are:

`API_KEY`
`OAUTH_CLIENT_ID`
`OAUTH_CLIENT_SECRET`
`OAUTH_REALM`
`OAUTH_APP_NAME`
`OAUTH2_REDIRECT_URL`
`OAUTH_ADDITIONAL_PARAMS`
`SWAGGER_JSON`
`API_URL`

You can set these `docker run` or `docker-compose`, like:

`docker run -p 80:8080 -e API_URL=http://petstore.swagger.io/v2/swagger.json swaggerapi/swagger-ui`

Or you can provide your own swagger.json on your host

```
docker run -p 80:8080 -e "SWAGGER_JSON=/foo/swagger.json" -v /bar:/foo swaggerapi/swagger-ui
```


##### Prerequisites
- Node 6.x
- NPM 3.x
Expand Down Expand Up @@ -84,6 +101,7 @@ To use swagger-ui's bundles, you should take a look at the [source of swagger-ui
const ui = SwaggerUIBundle({
url: "http://petstore.swagger.io/v2/swagger.json",
dom_id: '#swagger-ui',
oauth2RedirectUrl: 'http://localhost:3200/oauth2-redirect.html',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
Expand Down
10 changes: 10 additions & 0 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
const ui = SwaggerUIBundle({
url: "http://petstore.swagger.io/v2/swagger.json",
dom_id: '#swagger-ui',
oauth2RedirectUrl: 'http://localhost:3200/oauth2-redirect.html',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
Expand All @@ -86,6 +87,15 @@
})

window.ui = ui

ui.initOAuth({
clientId: "your-client-id",
clientSecret: "your-client-secret-if-required",
realm: "your-realms",
appName: "your-app-name",
scopeSeparator: " ",
additionalQueryStringParams: {}
})
}
</script>
</body>
Expand Down
4 changes: 3 additions & 1 deletion docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ replace_in_index () {
}

replace_or_delete_in_index () {
if [ -z "$2" ]; then
if [ -z "$2" ] || [ "$2" = "**None**" ]; then
sed -i "/$1/d" $INDEX_FILE
else
replace_in_index $1 $2
Expand All @@ -26,6 +26,8 @@ replace_or_delete_in_index your-client-id $OAUTH_CLIENT_ID
replace_or_delete_in_index your-client-secret-if-required $OAUTH_CLIENT_SECRET
replace_or_delete_in_index your-realms $OAUTH_REALM
replace_or_delete_in_index your-app-name $OAUTH_APP_NAME
replace_in_index 'http://localhost:3200/oauth2-redirect.html' $OAUTH2_REDIRECT_URL

if [ "$OAUTH_ADDITIONAL_PARAMS" != "**None**" ]; then
replace_in_index "additionalQueryStringParams: {}" "additionalQueryStringParams: {$OAUTH_ADDITIONAL_PARAMS}"
fi
Expand Down