Skip to content

Commit

Permalink
improve subdirectory support
Browse files Browse the repository at this point in the history
closes #53
  • Loading branch information
BeryJu committed Jul 29, 2023
1 parent 2661b9b commit a535916
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ This tool is full configured using environment variables.
- `OIDC_CLIENT_ID`: OAuth2 Client ID to use.
- `OIDC_CLIENT_SECRET`: OAuth2 Client Secret to use. Can be set to an empty string when only implicit flow is tested.
- `OIDC_ROOT_URL`: URL under which you access this Client. (default http://localhost:9009)

When using in a subdirectory, make sure to leave out any trailing slashes

- `OIDC_PROVIDER`: Optional URL that metadata is fetched from. The metadata is fetched on the first request to `/`
- `OIDC_SCOPES`: Scopes to request from the provider. Defaults to "openid,offline_access,profile,email"
- `OIDC_DO_REFRESH`: Whether refresh-token related checks are enabled (don't ask for a refresh token) (default: true)
Expand Down
17 changes: 11 additions & 6 deletions pkg/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"os"
"strings"
"time"
Expand Down Expand Up @@ -243,14 +244,18 @@ func logRequest(handler http.Handler) http.Handler {
}

func (c *OIDCClient) Run() {
baseUrl, err := url.Parse(Env("OIDC_ROOT_URL", "http://localhost:9009"))
if err != nil {
panic(err)
}
mux := http.NewServeMux()
mux.HandleFunc("/implicit/", c.implicit)
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.FS(static))))
mux.HandleFunc("/health", c.health)
mux.HandleFunc(baseUrl.Path+"/implicit/", c.implicit)
mux.Handle(baseUrl.Path+"/static/", http.StripPrefix("/static/", http.FileServer(http.FS(static))))
mux.HandleFunc(baseUrl.Path+"/health", c.health)
// Just to prevent favicon from triggering authorize
mux.HandleFunc("/favicon.ico", c.health)
mux.HandleFunc("/auth/callback", c.oauthCallback)
mux.HandleFunc("/", c.oauthInit)
mux.HandleFunc(baseUrl.Path+"/favicon.ico", c.health)
mux.HandleFunc(baseUrl.Path+"/auth/callback", c.oauthCallback)
mux.HandleFunc(baseUrl.Path+"/", c.oauthInit)

listen := Env("OIDC_BIND", "localhost:9009")

Expand Down

0 comments on commit a535916

Please sign in to comment.