I cannot save RefreshToken on session.
In the code below, refreshToken is constant, but Actually it is created by AWS Cognito.
Is there any workaround??
thank you
import(
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
store := cookie.NewStore([]byte("secret"))
router.Use(sessions.Sessions("mysession", store))
router.GET("ping", func(c *gin.Context) {
session := sessions.Default(c)
accessToken = "dfasdfasdf..."() //length is 1086
session.Set("at", accessToken)
refreshToken = "dfasdfasdf..."() //length is 1802
session.Set("at", refreshToken)
c.JSON(http.StatusOK, "pong")
})
router.GET("ping2", func(c *gin.Context) {
session := sessions.Default(c)
session := sessions.Default(c)
c.JSON(http.StatusCreated, gin.H{
"at": session.Get("at"),
"rt": session.Get("rt"),
})
c.JSON(http.StatusOK, "pong")
})
router.Run(":8080")
}
CodePudding user response:
you need to call session.Save()
after using session.Set
.
e.g.
session.Set("accessToken", accessToken)
session.Set("refreshToken", refreshToken)
session.Save()