Skip to content

Commit

Permalink
Fixed base URL redirect (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto authored Mar 10, 2022
1 parent 0f19428 commit 8feb611
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion login/authorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"net/url"
"path"

oauth2 "github.com/oxisto/oauth2go"
)
Expand Down Expand Up @@ -62,7 +63,7 @@ func (h *handler) handleAuthorize(w http.ResponseWriter, r *http.Request) {
params.Add("return_url", r.RequestURI)

// Redirect to our login page
http.Redirect(w, r, fmt.Sprintf("/login?%s", params.Encode()), http.StatusFound)
http.Redirect(w, r, fmt.Sprintf("%s?%s", path.Join(h.baseURL, "/login"), params.Encode()), http.StatusFound)
} else {
var params = url.Values{}
params.Add("code", h.srv.IssueCode(challenge))
Expand Down
3 changes: 2 additions & 1 deletion login/authorize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func Test_handler_handleAuthorize(t *testing.T) {
users: []*User{},
log: log.Default(),
pwh: bcryptHasher{},
baseURL: "/oauth/",
srv: oauth2.NewServer(":0", oauth2.WithClient("client", "secret", "/test")),
},
args: args{
Expand All @@ -167,7 +168,7 @@ func Test_handler_handleAuthorize(t *testing.T) {
wantCode: http.StatusFound,
wantHeaderRegexp: http.Header{
// Should redirect to login page but with this authorize endpoint as return URL
"Location": []string{"/login\\?return_url=%2Fauthorize%3Fclient_id%3Dclient%26redirect_uri%3D%2Ftest%26response_type%3Dcode%26code_challenge%3D0123456789%26code_challenge_method%3DS256"},
"Location": []string{"/oauth/login\\?return_url=%2Fauthorize%3Fclient_id%3Dclient%26redirect_uri%3D%2Ftest%26response_type%3Dcode%26code_challenge%3D0123456789%26code_challenge_method%3DS256"},
},
},
{
Expand Down

0 comments on commit 8feb611

Please sign in to comment.