This commit is contained in:
crusader 2018-03-12 16:39:18 +09:00
parent d8dba557e3
commit c38073b8d0

View File

@ -5,6 +5,7 @@ import (
"crypto/rsa"
"fmt"
"io/ioutil"
"log"
"time"
"encoding/json"
@ -78,6 +79,8 @@ func SignIn(ctx *fasthttp.RequestCtx) {
/* Create a map to store our claims */
claims := token.Claims.(jwt.MapClaims)
expireTime := time.Now().Add(time.Hour * 24)
/* Set token claims */
claims["iss"] = "overFlow"
claims["iat"] = time.Now().Unix()
@ -88,9 +91,15 @@ func SignIn(ctx *fasthttp.RequestCtx) {
/* Sign the token with our secret */
tokenString, _ := token.SignedString(signKey)
log.Printf("%s \n", tokenString)
var jwtCookie fasthttp.Cookie
jwtCookie.SetKey("AuthToken")
jwtCookie.SetValue(tokenString)
// jwtCookie.SetHTTPOnly(true)
jwtCookie.SetSecure(true)
jwtCookie.SetExpire(expireTime)
jwtCookie.SetPath("/")
ctx.Response.Header.SetCookie(&jwtCookie)
commons.SendRESTResponse(ctx, r)