mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 10:45:47 +08:00
Show error "Invalid JWT token".
This commit is contained in:
parent
55e0fe14ca
commit
df7ac93feb
@ -18,7 +18,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/astaxie/beego/context"
|
"github.com/astaxie/beego/context"
|
||||||
|
"github.com/casdoor/casdoor/controllers"
|
||||||
"github.com/casdoor/casdoor/object"
|
"github.com/casdoor/casdoor/object"
|
||||||
|
"github.com/casdoor/casdoor/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getSessionUser(ctx *context.Context) string {
|
func getSessionUser(ctx *context.Context) string {
|
||||||
@ -40,6 +42,16 @@ func setSessionUser(ctx *context.Context, user string) {
|
|||||||
ctx.Input.CruSession.SessionRelease(ctx.ResponseWriter)
|
ctx.Input.CruSession.SessionRelease(ctx.ResponseWriter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func returnRequest(ctx *context.Context, msg string) {
|
||||||
|
w := ctx.ResponseWriter
|
||||||
|
w.WriteHeader(200)
|
||||||
|
resp := &controllers.Response{Status: "error", Msg: msg}
|
||||||
|
_, err := w.Write([]byte(util.StructToJson(resp)))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func AutoLoginFilter(ctx *context.Context) {
|
func AutoLoginFilter(ctx *context.Context) {
|
||||||
query := ctx.Request.URL.RawQuery
|
query := ctx.Request.URL.RawQuery
|
||||||
// query == "?access_token=123"
|
// query == "?access_token=123"
|
||||||
@ -54,7 +66,8 @@ func AutoLoginFilter(ctx *context.Context) {
|
|||||||
|
|
||||||
claims, err := object.ParseJwtToken(accessToken)
|
claims, err := object.ParseJwtToken(accessToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
returnRequest(ctx, "Invalid JWT token")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
userId := fmt.Sprintf("%s/%s", claims.Organization, claims.Username)
|
userId := fmt.Sprintf("%s/%s", claims.Organization, claims.Username)
|
||||||
|
@ -128,6 +128,10 @@ class App extends Component {
|
|||||||
if (res.status === "ok") {
|
if (res.status === "ok") {
|
||||||
account = res.data;
|
account = res.data;
|
||||||
account.organization = res.data2;
|
account.organization = res.data2;
|
||||||
|
} else {
|
||||||
|
if (res.msg === "Invalid JWT token") {
|
||||||
|
Setting.showMessage("error", `Failed to sign in: ${res.msg}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user