Skip to content

Commit 55e6542

Browse files
authored
Merge pull request #38 from luizfonseca/fix/allow-additional-scopes-to-be-passed
fix: allow additional github scopes to be requested
2 parents c021e4a + 9abb557 commit 55e6542

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

README.md

Lines changed: 4 additions & 1 deletion
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. | | 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
@@ -105,7 +107,8 @@ You can follow the steps in the [GitHub documentation](https://docs.github.com/e
105107

106108
#### OAuth Scopes
107109
- For `ids` and `logins` you don't need extra scopes.
108-
- 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).
110+
- For `teams` you might need to request the `read:org` scope 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="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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package traefik_github_oauth_server
22

33
import (
44
"os"
5+
"strings"
56

67
"github.com/spf13/cast"
78
)
@@ -15,6 +16,7 @@ type Config struct {
1516
GitHubOAuthClientID string
1617
GitHubOAuthClientSecret string
1718
Addr string
19+
GithubOauthScopes []string
1820
}
1921

2022
func envWithDefault(key string, defaultValue string) string {
@@ -25,6 +27,15 @@ func envWithDefault(key string, defaultValue string) string {
2527
return value
2628
}
2729

30+
func githubOauthScopeConfigs() []string {
31+
scopesFromEnv := os.Getenv("GITHUB_OAUTH_SCOPES")
32+
if scopesFromEnv != "" {
33+
return strings.Split(scopesFromEnv, ",")
34+
}
35+
36+
return []string{}
37+
}
38+
2839
func NewConfigFromEnv() *Config {
2940
return &Config{
3041
ApiBaseURL: os.Getenv("API_BASE_URL"),
@@ -34,5 +45,6 @@ func NewConfigFromEnv() *Config {
3445
LogLevel: envWithDefault("LOG_LEVEL", "INFO"),
3546
GitHubOAuthClientID: os.Getenv("GITHUB_OAUTH_CLIENT_ID"),
3647
GitHubOAuthClientSecret: os.Getenv("GITHUB_OAUTH_CLIENT_SECRET"),
48+
GithubOauthScopes: githubOauthScopeConfigs(),
3749
}
3850
}

0 commit comments

Comments
 (0)