mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 12:30:19 +08:00
feat: return most backend API errors to frontend (#1836)
* feat: return most backend API errros to frontend Signed-off-by: yehong <239859435@qq.com> * refactor: reduce int type change Signed-off-by: yehong <239859435@qq.com> * feat: return err backend in token.go Signed-off-by: yehong <239859435@qq.com> --------- Signed-off-by: yehong <239859435@qq.com>
This commit is contained in:
@ -32,7 +32,12 @@ func AutoSigninFilter(ctx *context.Context) {
|
||||
accessToken := util.GetMaxLenStr(ctx.Input.Query("accessToken"), ctx.Input.Query("access_token"), parseBearerToken(ctx))
|
||||
|
||||
if accessToken != "" {
|
||||
token := object.GetTokenByAccessToken(accessToken)
|
||||
token, err := object.GetTokenByAccessToken(accessToken)
|
||||
if err != nil {
|
||||
responseError(ctx, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if token == nil {
|
||||
responseError(ctx, "Access token doesn't exist")
|
||||
return
|
||||
@ -44,7 +49,11 @@ func AutoSigninFilter(ctx *context.Context) {
|
||||
}
|
||||
|
||||
userId := util.GetId(token.Organization, token.User)
|
||||
application, _ := object.GetApplicationByUserId(fmt.Sprintf("app/%s", token.Application))
|
||||
application, _, err := object.GetApplicationByUserId(fmt.Sprintf("app/%s", token.Application))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
setSessionUser(ctx, userId)
|
||||
setSessionOidc(ctx, token.Scope, application.ClientId)
|
||||
return
|
||||
|
@ -72,7 +72,11 @@ func getUsernameByClientIdSecret(ctx *context.Context) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
application := object.GetApplicationByClientId(clientId)
|
||||
application, err := object.GetApplicationByClientId(clientId)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if application == nil || application.ClientSecret != clientSecret {
|
||||
return ""
|
||||
}
|
||||
|
@ -34,7 +34,12 @@ func CorsFilter(ctx *context.Context) {
|
||||
originConf := conf.GetConfigString("origin")
|
||||
|
||||
if origin != "" && originConf != "" && origin != originConf {
|
||||
if object.IsOriginAllowed(origin) {
|
||||
ok, err := object.IsOriginAllowed(origin)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if ok {
|
||||
ctx.Output.Header(headerAllowOrigin, origin)
|
||||
ctx.Output.Header(headerAllowMethods, "POST, GET, OPTIONS, DELETE")
|
||||
ctx.Output.Header(headerAllowHeaders, "Content-Type, Authorization")
|
||||
|
@ -43,7 +43,11 @@ func getUserByClientIdSecret(ctx *context.Context) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
application := object.GetApplicationByClientId(clientId)
|
||||
application, err := object.GetApplicationByClientId(clientId)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if application == nil || application.ClientSecret != clientSecret {
|
||||
return ""
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ import (
|
||||
var (
|
||||
oldStaticBaseUrl = "https://cdn.casbin.org"
|
||||
newStaticBaseUrl = conf.GetConfigString("staticBaseUrl")
|
||||
enableGzip, _ = conf.GetConfigBool("enableGzip")
|
||||
enableGzip = conf.GetConfigBool("enableGzip")
|
||||
)
|
||||
|
||||
func StaticFilter(ctx *context.Context) {
|
||||
|
Reference in New Issue
Block a user