How to deploy a internal used api document - OAuth2 protected swagger UI
Posted onInTutorialViews: Word count in article: 5.6kReading time ≈5 mins.
Now our company is to develop app. We need a internal API document platform help us corlaboration. After searching online, I found that most of open source API document project do not support auth. So I learned how to use OAuth2 Proxy protect our Swagger UI. In this toturial, I will use self managed Gitea as OAuth2 provider.
services: # OAuth2 Proxy service for Gitea authentication oauth2-proxy: image:quay.io/oauth2-proxy/oauth2-proxy:latest container_name:oauth2-proxy command: ---http-address=0.0.0.0:4180 ---upstream=http://swagger:8080 ---email-domain=* ---cookie-secure=true# Set to true in production with HTTPS ---cookie-secret=${COOKIE_SECRET} ---client-id=${CLIENT_ID} ---client-secret=${CLIENT_SECRET} ---provider=github ---redirect-url=https://docs.rui.ke/oauth2/callback ---provider-display-name=Gitea ---login-url=https://gitea.example.com/login/oauth/authorize ---redeem-url=https://gitea.example.com/login/oauth/access_token ---validate-url=https://gitea.example.com/api/v1/user/emails ---custom-templates-dir=/templates environment: -OAUTH2_PROXY_CLIENT_ID=${CLIENT_ID} -OAUTH2_PROXY_CLIENT_SECRET=${CLIENT_SECRET} -OAUTH2_PROXY_COOKIE_SECRET=${COOKIE_SECRET} volumes: -./templates:/templates:ro ports: -"127.0.0.1:1688:4180" depends_on: -swagger networks: -swagger-net restart:unless-stopped
# Swagger UI service swagger: image:swaggerapi/swagger-ui:latest container_name:swagger-ui environment: -SWAGGER_JSON=/spec/openapi.yaml# Path to your OpenAPI spec -BASE_URL=/ -PORT=8080 -VALIDATOR_URL= volumes: -/srv/swagger/spec:/spec:ro# Mount your OpenAPI spec file expose: -"8080" networks: -swagger-net restart:unless-stopped
networks: swagger-net: driver:bridge
1
vim .env
1 2 3
CLIENT_ID=your_client_id # get this from your gitea application CLIENT_SECRET=your_client_secret # get this from your gitea application COOKIE_SECRET=a_random_string