Skip to content

Commit 1ee68ad

Browse files
Add the ability to configure the scopes passed to the authorization request
Signed-off-by: Matthew DeVenny <matt@boxboat.com>
1 parent 20b621e commit 1ee68ad

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This repository builds a Docker Image that protects an upstream server using [Ok
1919

2020
### Optional
2121

22+
- `AUTH_SCOPE` - Defaults to `openid profile`. Okta token auth scopes - note if you override this `openid` is necessary for authentication requests.
2223
- `APP_POST_LOGIN_URL` - After authentication is complete, redirect to an application-specific URL. The `state` query parameter will hold the original URL.
2324
- `COOKIE_DOMAIN` - Defaults to current domain only. Set in order to allow use on subdomains.
2425
- `COOKIE_NAME` - Defaults to `okta-jwt`. The name of the cookie that holds the Identity Token

server.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type config struct {
3333
httpClient *http.Client
3434
issuer string //ISSUER
3535
ssoPath string //SSO_PATH
36+
authScope string //AUTH_SCOPE
3637
verifier *jwtverifier.JwtVerifier
3738
}
3839

@@ -90,6 +91,15 @@ func getConfig() *config {
9091
}
9192
}
9293

94+
authScope := os.Getenv("AUTH_SCOPE")
95+
if authScope == "" {
96+
authScope = "openid profile"
97+
} else {
98+
if !strings.Contains(authScope, "openid") {
99+
log.Fatalln("AUTH_SCOPE must contain openid")
100+
}
101+
}
102+
93103
httpClient := &http.Client{
94104
Timeout: requestTimeOutSeconds,
95105
}
@@ -153,6 +163,7 @@ func getConfig() *config {
153163
httpClient: httpClient,
154164
issuer: issuer,
155165
ssoPath: ssoPath,
166+
authScope: authScope,
156167
verifier: verifier,
157168
}
158169
}
@@ -555,7 +566,7 @@ func getJWT(r *http.Request, code string, conf *config) (string, error) {
555566
"&client_secret=" + url.QueryEscape(conf.clientSecret) +
556567
"&redirect_uri=" + url.QueryEscape(loginRedirect) +
557568
"&grant_type=authorization_code" +
558-
"&scope=openid profile")
569+
"&scope=" + url.QueryEscape(conf.authScope))
559570

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

0 commit comments

Comments
 (0)