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", Name: "quic",
Usage: "enable 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{ &cli.StringSliceFlag{
EnvVars: []string{"WOODPECKER_ADMIN"}, EnvVars: []string{"WOODPECKER_ADMIN"},
Name: "admin", Name: "admin",
@ -512,4 +506,18 @@ var flags = []cli.Flag{
Name: "keepalive-min-time", Name: "keepalive-min-time",
Usage: "server-side enforcement policy on the minimum amount of time a client should wait before sending a keepalive ping.", 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.Key = c.String("server-key")
server.Config.Server.Pass = c.String("agent-secret") server.Config.Server.Pass = c.String("agent-secret")
server.Config.Server.Host = c.String("server-host") 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.Port = c.String("server-addr")
server.Config.Server.Docs = c.String("docs") server.Config.Server.Docs = c.String("docs")
server.Config.Server.SessionExpires = c.Duration("session-expires") server.Config.Server.SessionExpires = c.Duration("session-expires")

View file

@ -52,6 +52,7 @@ var Config = struct {
Server struct { Server struct {
Key string Key string
Cert string Cert string
OAuthHost string
Host string Host string
Port string Port string
Pass 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), AuthURL: fmt.Sprintf(authorizeTokenURL, c.URL),
TokenURL: fmt.Sprintf(accessTokenURL, 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 // get the OAuth errors

View file

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

View file

@ -95,7 +95,7 @@ func (g *Gitlab) Login(ctx context.Context, res http.ResponseWriter, req *http.R
Scope: defaultScope, Scope: defaultScope,
AuthURL: fmt.Sprintf("%s/oauth/authorize", g.URL), AuthURL: fmt.Sprintf("%s/oauth/authorize", g.URL),
TokenURL: fmt.Sprintf("%s/oauth/token", 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 // get the OAuth errors