Skip to content

Commit 1be557a

Browse files
committed
[feat] support custom GitHub OAuth2 auth and token URLs
1 parent c87f489 commit 1be557a

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

examples/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,31 @@ In the case of running zot with openid enabled behind a proxy/load balancer http
362362
```
363363
This config value will be used by oauth2/openid clients to redirect back to zot.
364364

365+
### OAuth2 (GitHub) login with custom URL's (GitHub Enterprise)
366+
367+
In the case of running zot with GitHub Enterprise, auth and token URL's should be provided.
368+
369+
```
370+
"http": {
371+
"address": "0.0.0.0",
372+
"port": "8080",
373+
"externalUrl: "https://zot.example.com",
374+
"auth": {
375+
"openid": {
376+
"providers": {
377+
"github": {
378+
"clientid": <client_id>,
379+
"clientsecret": <client_secret>,
380+
"authurl": <auth_url>,
381+
"tokenurl": <token_url>,
382+
"scopes": ["read:org", "user", "repo"]
383+
}
384+
}
385+
}
386+
}
387+
}
388+
```
389+
365390
### Session based login
366391

367392
Whenever a user logs in zot using any of the auth options available(basic auth/openid) zot will set a 'session' cookie on its response.

pkg/api/authn.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,12 +587,24 @@ func NewRelyingPartyGithub(config *config.Config, provider string, hashKey, encr
587587
_, clientID, clientSecret, redirectURI, scopes,
588588
options := getRelyingPartyArgs(config, provider, hashKey, encryptKey, log)
589589

590+
var endpoint oauth2.Endpoint
591+
592+
// Use custom endpoints if provided, otherwise fallback to GitHub's endpoints
593+
if provider := config.HTTP.Auth.OpenID.Providers[provider]; provider.AuthUrl != "" && provider.TokenUrl != "" {
594+
endpoint = oauth2.Endpoint{
595+
AuthURL: provider.AuthUrl,
596+
TokenURL: provider.TokenUrl,
597+
}
598+
} else {
599+
endpoint = githubOAuth.Endpoint
600+
}
601+
590602
rpConfig := &oauth2.Config{
591603
ClientID: clientID,
592604
ClientSecret: clientSecret,
593605
RedirectURL: redirectURI,
594606
Scopes: scopes,
595-
Endpoint: githubOAuth.Endpoint,
607+
Endpoint: endpoint,
596608
}
597609

598610
relyingParty, err := rp.NewRelyingPartyOAuth(rpConfig, options...)

pkg/api/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ type OpenIDProviderConfig struct {
100100
ClientSecret string
101101
KeyPath string
102102
Issuer string
103+
AuthUrl string
104+
TokenUrl string
103105
Scopes []string
104106
}
105107

0 commit comments

Comments
 (0)