mirror of
https://github.com/openziti/zrok.git
synced 2025-06-20 17:58:50 +02:00
redundant oauth configuration cleanup (#404)
This commit is contained in:
parent
d0a9353872
commit
c4f9cecd99
@ -18,11 +18,10 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type OauthConfig struct {
|
type OauthConfig struct {
|
||||||
Host string
|
RedirectHost string
|
||||||
Port int
|
RedirectPort int
|
||||||
RedirectUrl string
|
HashKeyRaw string `cf:"+secret"`
|
||||||
HashKeyRaw string `cf:"+secret"`
|
Providers []*OauthProviderConfig
|
||||||
Providers []*OauthProviderConfig
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (oc *OauthConfig) GetProvider(name string) *OauthProviderConfig {
|
func (oc *OauthConfig) GetProvider(name string) *OauthProviderConfig {
|
||||||
@ -65,6 +64,6 @@ func configureOauthHandlers(ctx context.Context, cfg *Config, tls bool) error {
|
|||||||
if err := configureGithubOauth(cfg.Oauth, tls); err != nil {
|
if err := configureGithubOauth(cfg.Oauth, tls); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
zhttp.StartServer(ctx, fmt.Sprintf("%s:%d", strings.Split(cfg.Address, ":")[0], cfg.Oauth.Port))
|
zhttp.StartServer(ctx, fmt.Sprintf("%s:%d", strings.Split(cfg.Address, ":")[0], cfg.Oauth.RedirectPort))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -34,12 +34,11 @@ func configureGithubOauth(cfg *OauthConfig, tls bool) error {
|
|||||||
}
|
}
|
||||||
clientID := providerCfg.ClientId
|
clientID := providerCfg.ClientId
|
||||||
callbackPath := "/github/oauth"
|
callbackPath := "/github/oauth"
|
||||||
port := cfg.Port
|
redirectUrl := fmt.Sprintf("%s://%s", scheme, cfg.RedirectHost)
|
||||||
redirectUrl := fmt.Sprintf("%s://%s", scheme, cfg.RedirectUrl)
|
|
||||||
rpConfig := &oauth2.Config{
|
rpConfig := &oauth2.Config{
|
||||||
ClientID: clientID,
|
ClientID: clientID,
|
||||||
ClientSecret: providerCfg.ClientSecret,
|
ClientSecret: providerCfg.ClientSecret,
|
||||||
RedirectURL: fmt.Sprintf("%v:%v%v", redirectUrl, port, callbackPath),
|
RedirectURL: fmt.Sprintf("%v:%v%v", redirectUrl, cfg.RedirectPort, callbackPath),
|
||||||
Scopes: []string{"user:email"},
|
Scopes: []string{"user:email"},
|
||||||
Endpoint: githubOAuth.Endpoint,
|
Endpoint: githubOAuth.Endpoint,
|
||||||
}
|
}
|
||||||
|
@ -35,12 +35,11 @@ func configureGoogleOauth(cfg *OauthConfig, tls bool) error {
|
|||||||
|
|
||||||
clientID := providerCfg.ClientId
|
clientID := providerCfg.ClientId
|
||||||
callbackPath := "/google/oauth"
|
callbackPath := "/google/oauth"
|
||||||
port := cfg.Port
|
redirectUrl := fmt.Sprintf("%s://%s", scheme, cfg.RedirectHost)
|
||||||
redirectUrl := fmt.Sprintf("%s://%s", scheme, cfg.RedirectUrl)
|
|
||||||
rpConfig := &oauth2.Config{
|
rpConfig := &oauth2.Config{
|
||||||
ClientID: clientID,
|
ClientID: clientID,
|
||||||
ClientSecret: providerCfg.ClientSecret,
|
ClientSecret: providerCfg.ClientSecret,
|
||||||
RedirectURL: fmt.Sprintf("%v:%v%v", redirectUrl, port, callbackPath),
|
RedirectURL: fmt.Sprintf("%v:%v%v", redirectUrl, cfg.RedirectPort, callbackPath),
|
||||||
Scopes: []string{"https://www.googleapis.com/auth/userinfo.email"},
|
Scopes: []string{"https://www.googleapis.com/auth/userinfo.email"},
|
||||||
Endpoint: googleOauth.Endpoint,
|
Endpoint: googleOauth.Endpoint,
|
||||||
}
|
}
|
||||||
|
@ -348,7 +348,7 @@ func basicAuthRequired(w http.ResponseWriter, realm string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func oauthLoginRequired(w http.ResponseWriter, r *http.Request, shrToken string, pcfg *Config, provider, target string, authCheckInterval time.Duration) {
|
func oauthLoginRequired(w http.ResponseWriter, r *http.Request, shrToken string, pcfg *Config, provider, target string, authCheckInterval time.Duration) {
|
||||||
http.Redirect(w, r, fmt.Sprintf("http://%s.%s:%d/%s/login?targethost=%s&checkInterval=%s", shrToken, pcfg.Oauth.Host, pcfg.Oauth.Port, provider, url.QueryEscape(target), authCheckInterval.String()), http.StatusFound)
|
http.Redirect(w, r, fmt.Sprintf("http://%s.%s:%d/%s/login?targethost=%s&checkInterval=%s", shrToken, pcfg.Oauth.RedirectHost, pcfg.Oauth.RedirectPort, provider, url.QueryEscape(target), authCheckInterval.String()), http.StatusFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolveService(hostMatch string, host string) string {
|
func resolveService(hostMatch string, host string) string {
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
#host_match: zrok.io
|
#host_match: zrok.io
|
||||||
|
|
||||||
#oauth:
|
#oauth:
|
||||||
# port: 28080
|
# redirect_host: zrok.io
|
||||||
# redirect_url: zrok.io
|
# redirect_port: 28080
|
||||||
# hash_key_raw: "test1234test1234"
|
# hash_key_raw: "test1234test1234"
|
||||||
# providers:
|
# providers:
|
||||||
# - name: google
|
# - name: google
|
||||||
|
Loading…
x
Reference in New Issue
Block a user