mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-23 08:56:29 +00:00
Merge pull request #39 from laszlocph/intended-url
Persist intended URL through the OAuth flow
This commit is contained in:
commit
0e77a5b519
4 changed files with 432 additions and 507 deletions
|
@ -105,7 +105,7 @@ type client struct {
|
|||
|
||||
// Login authenticates the session and returns the remote user details.
|
||||
func (c *client) Login(res http.ResponseWriter, req *http.Request) (*model.User, error) {
|
||||
config := c.newConfig(httputil.GetURL(req))
|
||||
config := c.newConfig(req)
|
||||
|
||||
// get the OAuth errors
|
||||
if err := req.FormValue("error"); err != "" {
|
||||
|
@ -348,7 +348,16 @@ func (c *client) newContext() context.Context {
|
|||
}
|
||||
|
||||
// helper function to return the GitHub oauth2 config
|
||||
func (c *client) newConfig(redirect string) *oauth2.Config {
|
||||
func (c *client) newConfig(req *http.Request) *oauth2.Config {
|
||||
var redirect string
|
||||
|
||||
intendedURL := req.URL.Query()["url"]
|
||||
if len(intendedURL) > 0 {
|
||||
redirect = fmt.Sprintf("%s/authorize?url=%s", httputil.GetURL(req), intendedURL[0])
|
||||
} else {
|
||||
redirect = fmt.Sprintf("%s/authorize", httputil.GetURL(req))
|
||||
}
|
||||
|
||||
return &oauth2.Config{
|
||||
ClientID: c.Client,
|
||||
ClientSecret: c.Secret,
|
||||
|
@ -357,7 +366,7 @@ func (c *client) newConfig(redirect string) *oauth2.Config {
|
|||
AuthURL: fmt.Sprintf("%s/login/oauth/authorize", c.URL),
|
||||
TokenURL: fmt.Sprintf("%s/login/oauth/access_token", c.URL),
|
||||
},
|
||||
RedirectURL: fmt.Sprintf("%s/authorize", redirect),
|
||||
RedirectURL: redirect,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,12 @@ func HandleLogin(c *gin.Context) {
|
|||
if err := r.FormValue("error"); err != "" {
|
||||
http.Redirect(w, r, "/login/error?code="+err, 303)
|
||||
} else {
|
||||
http.Redirect(w, r, "/authorize", 303)
|
||||
intendedURL := r.URL.Query()["url"]
|
||||
if len(intendedURL) > 0 {
|
||||
http.Redirect(w, r, "/authorize?url="+intendedURL[0], 303)
|
||||
} else {
|
||||
http.Redirect(w, r, "/authorize", 303)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,8 +141,13 @@ func HandleAuth(c *gin.Context) {
|
|||
}
|
||||
|
||||
httputil.SetCookie(c.Writer, c.Request, "user_sess", tokenstr)
|
||||
c.Redirect(303, "/")
|
||||
|
||||
intendedURL := c.Request.URL.Query()["url"]
|
||||
if len(intendedURL) > 0 {
|
||||
c.Redirect(303, intendedURL[0])
|
||||
} else {
|
||||
c.Redirect(303, "/")
|
||||
}
|
||||
}
|
||||
|
||||
func GetLogout(c *gin.Context) {
|
||||
|
|
904
vendor/github.com/laszlocph/drone-ui/dist/dist_gen.go
generated
vendored
904
vendor/github.com/laszlocph/drone-ui/dist/dist_gen.go
generated
vendored
File diff suppressed because one or more lines are too long
6
vendor/vendor.json
vendored
6
vendor/vendor.json
vendored
|
@ -425,10 +425,10 @@
|
|||
"revisionTime": "2016-05-04T02:26:26Z"
|
||||
},
|
||||
{
|
||||
"checksumSHA1": "R/gRUF6hXEFbDGSIOKt6VdCPwHE=",
|
||||
"checksumSHA1": "0EDT2W8Q8n8qx0eTWKpYy1Zt/6c=",
|
||||
"path": "github.com/laszlocph/drone-ui/dist",
|
||||
"revision": "cb186a44722ce1a6a6795aa36ebce1a53375e118",
|
||||
"revisionTime": "2019-06-26T08:23:24Z",
|
||||
"revision": "81a0263ee4e9b251a5741270b8b4120190fa6747",
|
||||
"revisionTime": "2019-06-27T06:23:05Z",
|
||||
"version": "master",
|
||||
"versionExact": "master"
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue