mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
Support fastAutoSignin by backend redirection
This commit is contained in:
parent
1732cd8538
commit
6ef2b51782
@ -26,6 +26,7 @@ import (
|
|||||||
|
|
||||||
"github.com/beego/beego/context"
|
"github.com/beego/beego/context"
|
||||||
"github.com/casdoor/casdoor/conf"
|
"github.com/casdoor/casdoor/conf"
|
||||||
|
"github.com/casdoor/casdoor/object"
|
||||||
"github.com/casdoor/casdoor/util"
|
"github.com/casdoor/casdoor/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -46,6 +47,46 @@ func getWebBuildFolder() string {
|
|||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fastAutoSignin(ctx *context.Context) (string, error) {
|
||||||
|
userId := getSessionUser(ctx)
|
||||||
|
if userId == "" {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
clientId := ctx.Input.Query("client_id")
|
||||||
|
responseType := ctx.Input.Query("response_type")
|
||||||
|
redirectUri := ctx.Input.Query("redirect_uri")
|
||||||
|
scope := ctx.Input.Query("scope")
|
||||||
|
state := ctx.Input.Query("state")
|
||||||
|
nonce := ""
|
||||||
|
codeChallenge := ""
|
||||||
|
if clientId == "" || responseType != "code" || redirectUri == "" {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
application, err := object.GetApplicationByClientId(clientId)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if application == nil {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if !application.EnableAutoSignin {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
code, err := object.GetOAuthCode(userId, clientId, responseType, redirectUri, scope, state, nonce, codeChallenge, ctx.Request.Host, getAcceptLanguage(ctx))
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
} else if code.Message != "" {
|
||||||
|
return "", fmt.Errorf(code.Message)
|
||||||
|
}
|
||||||
|
|
||||||
|
res := fmt.Sprintf("%s?code=%s&state=%s", redirectUri, code.Code, state)
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
func StaticFilter(ctx *context.Context) {
|
func StaticFilter(ctx *context.Context) {
|
||||||
urlPath := ctx.Request.URL.Path
|
urlPath := ctx.Request.URL.Path
|
||||||
|
|
||||||
@ -63,6 +104,19 @@ func StaticFilter(ctx *context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if urlPath == "/login/oauth/authorize" {
|
||||||
|
redirectUrl, err := fastAutoSignin(ctx)
|
||||||
|
if err != nil {
|
||||||
|
responseError(ctx, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if redirectUrl != "" {
|
||||||
|
http.Redirect(ctx.ResponseWriter, ctx.Request, redirectUrl, http.StatusFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
webBuildFolder := getWebBuildFolder()
|
webBuildFolder := getWebBuildFolder()
|
||||||
path := webBuildFolder
|
path := webBuildFolder
|
||||||
if urlPath == "/" {
|
if urlPath == "/" {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user