Skip to content

Commit

Permalink
Merge pull request #13 from IRONICBo/feat/mvp-20240119
Browse files Browse the repository at this point in the history
Fix: fix redirect url.
  • Loading branch information
Baihhh authored Jan 31, 2024
2 parents 0fcfb2e + d816e4f commit 30aeb46
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/gopcomm/community_yap.gox
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ get "/login", ctx => {
// redirectURL := ctx.URL.Query().Get("redirect_url")
// Get current request page URL from
// Concatenate the current request page URL from refer
redirectURL := fmt.Sprintf("%s/%s", ctx.Request.Referer() + "callback")
redirectURL := fmt.Sprintf("%s/%s", ctx.Request.Referer(), "callback")

loginURL := community.RedirectToCasdoor(redirectURL)
ctx.Redirect loginURL, http.StatusFound
Expand Down
2 changes: 1 addition & 1 deletion cmd/gopcomm/gop_autogen.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func (this *community) MainEntry() {
//line cmd/gopcomm/community_yap.gox:407:1
this.Get("/login", func(ctx *yap.Context) {
//line cmd/gopcomm/community_yap.gox:412:1
redirectURL := fmt.Sprintf("%s/%s", ctx.Request.Referer()+"callback")
redirectURL := fmt.Sprintf("%s/%s", ctx.Request.Referer(), "callback")
//line cmd/gopcomm/community_yap.gox:414:1
loginURL := this.community.RedirectToCasdoor(redirectURL)
//line cmd/gopcomm/community_yap.gox:415:1
Expand Down
19 changes: 12 additions & 7 deletions internal/core/community.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"database/sql"
"fmt"
"net/url"
"os"
"strconv"
"time"
Expand Down Expand Up @@ -404,19 +405,23 @@ func casdoorConfigInit() *CasdoorConfig {

func (a *Community) RedirectToCasdoor(redirect string) (loginURL string) {
// TODO: Check whitelist from referer
ResponseType := "code"
Scope := "read"
State := "casdoor"
responseType := "code"
scope := "read"
state := "casdoor"
redirectEncodeURL := url.QueryEscape(redirect)

loginURL = fmt.Sprintf(
"%s/login/oauth/authorize?client_id=%s&response_type=%s&redirect_uri=%s&scope=%s&state=%s",
a.casdoorConfig.endPoint,
a.casdoorConfig.clientId,
ResponseType,
redirect,
Scope,
State,
responseType,
redirectEncodeURL,
scope,
state,
)

fmt.Println("loginURL", loginURL)

return loginURL
}

Expand Down

0 comments on commit 30aeb46

Please sign in to comment.