Add flag to set oauth redirect host in dev mode (#586)

This commit is contained in:
Anbraten 2021-12-13 20:22:09 +01:00 committed by GitHub
parent ad509fd86f
commit 3bee9044f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 10 deletions

View file

@ -79,12 +79,6 @@ var flags = []cli.Flag{
Name: "quic",
Usage: "enable quic",
},
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_WWW_PROXY"},
Name: "www-proxy",
Usage: "serve the website by using a proxy (used for development)",
Hidden: true,
},
&cli.StringSliceFlag{
EnvVars: []string{"WOODPECKER_ADMIN"},
Name: "admin",
@ -512,4 +506,18 @@ var flags = []cli.Flag{
Name: "keepalive-min-time",
Usage: "server-side enforcement policy on the minimum amount of time a client should wait before sending a keepalive ping.",
},
// development flags
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_DEV_WWW_PROXY"},
Name: "www-proxy",
Usage: "serve the website by using a proxy (used for development)",
Hidden: true,
},
&cli.StringFlag{
EnvVars: []string{"WOODPECKER_DEV_OAUTH_HOST"},
Name: "server-dev-oauth-host",
Usage: "server fully qualified url (<scheme>://<host>) used for oauth redirect (used for development)",
Value: "",
Hidden: true,
},
}

View file

@ -290,6 +290,11 @@ func setupEvilGlobals(c *cli.Context, v store.Store, r remote.Remote) {
server.Config.Server.Key = c.String("server-key")
server.Config.Server.Pass = c.String("agent-secret")
server.Config.Server.Host = c.String("server-host")
if c.IsSet("server-dev-oauth-host") {
server.Config.Server.OAuthHost = c.String("server-dev-oauth-host")
} else {
server.Config.Server.OAuthHost = c.String("server-host")
}
server.Config.Server.Port = c.String("server-addr")
server.Config.Server.Docs = c.String("docs")
server.Config.Server.SessionExpires = c.Duration("session-expires")

View file

@ -52,6 +52,7 @@ var Config = struct {
Server struct {
Key string
Cert string
OAuthHost string
Host string
Port string
Pass string

View file

@ -99,7 +99,7 @@ func (c *Gitea) Login(ctx context.Context, w http.ResponseWriter, req *http.Requ
AuthURL: fmt.Sprintf(authorizeTokenURL, c.URL),
TokenURL: fmt.Sprintf(accessTokenURL, c.URL),
},
RedirectURL: fmt.Sprintf("%s/authorize", server.Config.Server.Host),
RedirectURL: fmt.Sprintf("%s/authorize", server.Config.Server.OAuthHost),
}
// get the OAuth errors

View file

@ -338,9 +338,9 @@ func (c *client) newConfig(req *http.Request) *oauth2.Config {
intendedURL := req.URL.Query()["url"]
if len(intendedURL) > 0 {
redirect = fmt.Sprintf("%s/authorize?url=%s", server.Config.Server.Host, intendedURL[0])
redirect = fmt.Sprintf("%s/authorize?url=%s", server.Config.Server.OAuthHost, intendedURL[0])
} else {
redirect = fmt.Sprintf("%s/authorize", server.Config.Server.Host)
redirect = fmt.Sprintf("%s/authorize", server.Config.Server.OAuthHost)
}
return &oauth2.Config{

View file

@ -95,7 +95,7 @@ func (g *Gitlab) Login(ctx context.Context, res http.ResponseWriter, req *http.R
Scope: defaultScope,
AuthURL: fmt.Sprintf("%s/oauth/authorize", g.URL),
TokenURL: fmt.Sprintf("%s/oauth/token", g.URL),
RedirectURL: fmt.Sprintf("%s/authorize", server.Config.Server.Host),
RedirectURL: fmt.Sprintf("%s/authorize", server.Config.Server.OAuthHost),
}
// get the OAuth errors