We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
package main import ( "github.com/kataras/iris/v12" "github.com/kataras/iris/v12/apps" "github.com/kataras/jwt" "github.com/rs/cors" "log" "time" ) type UserClaims struct { ID int `json:"id"` Username string `json:"username"` } func main() { app := iris.New() c := cors.New(cors.Options{ AllowedOrigins: []string{"*"}, AllowCredentials: true, Debug: false, }) app.WrapRouter(c.ServeHTTP) app.Get("/a", func(ctx iris.Context) { var sharedKey = []byte("sercrethatmaycontainch@r$32chars") claims := UserClaims{ ID: 123456, Username: "Username", } accessToken, tErr := jwt.Sign(jwt.HS256, sharedKey, claims, jwt.MaxAge(20000*time.Hour)) if tErr != nil { log.Println("accessToken err") } refreshToken, rErr := jwt.Sign(jwt.HS256, sharedKey, claims, jwt.MaxAge(30000*time.Hour)) if rErr != nil { log.Println("refreshToken err") } _ = ctx.JSON(iris.Map{ "accessToken": accessToken, "refreshToken": refreshToken, }) }) app.Get("/b", func(ctx iris.Context) { type RefreshToken struct { RefreshToken string `json:"refreshToken"` } var rt RefreshToken if err := ctx.ReadJSON(&rt); err != nil { apps.Get().Logger().Error("---------------- 读取参数失败", err.Error()) } var sharedKey = []byte("sercrethatmaycontainch@r$32chars") verifiedToken, err := jwt.Verify(jwt.HS256, sharedKey, []byte(rt.RefreshToken)) if err != nil { log.Println("1111111111111111111111111111111", err) } else { var u UserClaims err = verifiedToken.Claims(&u) log.Println(u.ID, " -------------------------- ", u.Username) log.Println("2222222222222222222222222222222") } }) _ = app.Listen(":9000", nil) }
Hello, is there a typo there?
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Hello, is there a typo there?
The text was updated successfully, but these errors were encountered: