Skip to content

Commit 7496505

Browse files
committed
fix: allow additional github scopes to be requested
1 parent c021e4a commit 7496505

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ providing a more secure way for users to access protected routes.
6363
|------------------------------|-------------------------------------------------------------------------------|---------|----------|
6464
| `GITHUB_OAUTH_CLIENT_ID` | The GitHub OAuth App client id | | Yes |
6565
| `GITHUB_OAUTH_CLIENT_SECRET` | The GitHub OAuth App client secret | | Yes |
66+
| `GITHUB_OAUTH_SCOPES` | Additional scopes to be added to the Oauth workflow. "user" is always added. | "user" | No |
6667
| `API_BASE_URL` | The base URL of the Traefik GitHub OAuth server | | Yes |
6768
| `API_SECRET_KEY` | The api secret key. You can ignore this if you are using the internal network | | No |
6869
| `SERVER_ADDRESS` | The server address | `:80` | No |
@@ -89,6 +90,7 @@ whitelist:
8990
# The list of GitHub user ids that are whitelisted to access the resources
9091
ids:
9192
- 996
93+
9294
# The list of GitHub user logins that are whitelisted to access the resources
9395
logins:
9496
- luizfonseca
@@ -106,6 +108,7 @@ You can follow the steps in the [GitHub documentation](https://docs.github.com/e
106108
#### OAuth Scopes
107109
- For `ids` and `logins` you don't need extra scopes.
108110
- For `teams` you will need to request the `read:org`, `user` or `repo` scopes from the user. See the [documentation](https://docs.github.com/en/rest/teams/teams?apiVersion=2022-11-28#list-teams-for-the-authenticated-user).
111+
- You can do so by updating the `GITHUB_OAUTH_SCOPES` environment variable with the desired additional scopes, e.g. `GITHUB_OAUTH_SCOPES="repo,read:org"` via the **Server Configuration**.
109112

110113

111114
## License

internal/app/traefik-github-oauth-server/app.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func NewApp(
6363
ClientID: config.GitHubOAuthClientID,
6464
ClientSecret: config.GitHubOAuthClientSecret,
6565
Endpoint: oauth2github.Endpoint,
66+
Scopes: config.GithubOauthScopes,
6667
},
6768
AuthRequestManager: authRequestManager,
6869
Logger: logger,

internal/app/traefik-github-oauth-server/config.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package traefik_github_oauth_server
22

33
import (
44
"os"
5+
"slices"
6+
"strings"
57

68
"github.com/spf13/cast"
79
)
@@ -15,6 +17,7 @@ type Config struct {
1517
GitHubOAuthClientID string
1618
GitHubOAuthClientSecret string
1719
Addr string
20+
GithubOauthScopes []string
1821
}
1922

2023
func envWithDefault(key string, defaultValue string) string {
@@ -25,6 +28,20 @@ func envWithDefault(key string, defaultValue string) string {
2528
return value
2629
}
2730

31+
func githubOauthScopeConfigs() []string {
32+
// Default scopes
33+
scopes := []string{"user"}
34+
35+
// Add additional scopes
36+
scopesFromEnv := os.Getenv("GITHUB_OAUTH_SCOPES")
37+
if scopesFromEnv != "" {
38+
sp := strings.Split(scopesFromEnv, ",")
39+
scopes = slices.Concat(scopes, sp)
40+
}
41+
42+
return scopes
43+
}
44+
2845
func NewConfigFromEnv() *Config {
2946
return &Config{
3047
ApiBaseURL: os.Getenv("API_BASE_URL"),
@@ -34,5 +51,6 @@ func NewConfigFromEnv() *Config {
3451
LogLevel: envWithDefault("LOG_LEVEL", "INFO"),
3552
GitHubOAuthClientID: os.Getenv("GITHUB_OAUTH_CLIENT_ID"),
3653
GitHubOAuthClientSecret: os.Getenv("GITHUB_OAUTH_CLIENT_SECRET"),
54+
GithubOauthScopes: githubOauthScopeConfigs(),
3755
}
3856
}

0 commit comments

Comments
 (0)