Skip to content

Commit

Permalink
Add the ability to configure the scopes passed to the authorization r…
Browse files Browse the repository at this point in the history
…equest

Signed-off-by: Matthew DeVenny <[email protected]>
  • Loading branch information
matthewdevenny committed Dec 7, 2023
1 parent 20b621e commit a499e53
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This repository builds a Docker Image that protects an upstream server using [Ok

### Optional

- `AUTH_SCOPE` - Defaults to `openid profile`. Okta token auth scopes - note if you override this `openid` is necessary for authentication requests.
- `APP_POST_LOGIN_URL` - After authentication is complete, redirect to an application-specific URL. The `state` query parameter will hold the original URL.
- `COOKIE_DOMAIN` - Defaults to current domain only. Set in order to allow use on subdomains.
- `COOKIE_NAME` - Defaults to `okta-jwt`. The name of the cookie that holds the Identity Token
Expand Down
15 changes: 13 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type config struct {
httpClient *http.Client
issuer string //ISSUER
ssoPath string //SSO_PATH
authScope string //AUTH_SCOPE
verifier *jwtverifier.JwtVerifier
}

Expand Down Expand Up @@ -90,6 +91,15 @@ func getConfig() *config {
}
}

authScope := os.Getenv("AUTH_SCOPE")
if authScope == "" {
authScope = "openid profile"
} else {
if !strings.Contains(authScope, "openid") {
log.Fatalln("AUTH_SCOPE must contain openid")
}
}

httpClient := &http.Client{
Timeout: requestTimeOutSeconds,
}
Expand Down Expand Up @@ -153,6 +163,7 @@ func getConfig() *config {
httpClient: httpClient,
issuer: issuer,
ssoPath: ssoPath,
authScope: authScope,
verifier: verifier,
}
}
Expand Down Expand Up @@ -555,7 +566,7 @@ func getJWT(r *http.Request, code string, conf *config) (string, error) {
"&client_secret=" + url.QueryEscape(conf.clientSecret) +
"&redirect_uri=" + url.QueryEscape(loginRedirect) +
"&grant_type=authorization_code" +
"&scope=openid profile")
"&authScope=" + url.QueryEscape(conf.authScope))

req, err := http.NewRequest("POST", conf.endpointToken, bytes.NewBuffer(reqBody))
if err != nil {
Expand Down Expand Up @@ -662,7 +673,7 @@ func redirectURL(r *http.Request, conf *config, requestURI string) string {
return conf.endpointAuthorize +
"?client_id=" + url.QueryEscape(conf.clientID) +
"&response_type=code" +
"&scope=openid profile" +
"&authScope=" + url.QueryEscape(conf.authScope) +
"&nonce=123" +
"&redirect_uri=" + url.QueryEscape(loginRedirect) +
"&state=" + url.QueryEscape(requestURLStr)
Expand Down

0 comments on commit a499e53

Please sign in to comment.