This commit is contained in:
crusader 2017-09-05 16:57:01 +09:00
parent d92eac5727
commit e1433246ca
2 changed files with 7 additions and 6 deletions

View File

@ -4,7 +4,7 @@
"tls": false "tls": false
}, },
"auth": { "auth": {
"signingKey": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" "signingKey": "tWB0lUXiCwX4U3qsJZcZ10mKvEH793RHkTJDbDuZVshQTk4uNB6ck59UQ96lhsRi4XNUiEnlIbP8XYQMPabeNtERX3iyHeDcwocgUVAor1nkAajYeq1gNyJszGpMhEOT"
}, },
"grpc": { "grpc": {
"addr": "127.0.0.1:50006", "addr": "127.0.0.1:50006",

View File

@ -7,13 +7,12 @@ import (
"encoding/json" "encoding/json"
"log" "log"
"git.loafle.net/commons_go/config"
"git.loafle.net/overflow/overflow_server_app/grpc" "git.loafle.net/overflow/overflow_server_app/grpc"
jwt "github.com/dgrijalva/jwt-go" jwt "github.com/dgrijalva/jwt-go"
"github.com/valyala/fasthttp" "github.com/valyala/fasthttp"
) )
var ofSigningKey = []byte("secret")
func SignIn(ctx *fasthttp.RequestCtx) { func SignIn(ctx *fasthttp.RequestCtx) {
var err error var err error
//signinId := string(ctx.FormValue("signinId")) //signinId := string(ctx.FormValue("signinId"))
@ -51,12 +50,14 @@ func SignIn(ctx *fasthttp.RequestCtx) {
claims := token.Claims.(jwt.MapClaims) claims := token.Claims.(jwt.MapClaims)
/* Set token claims */ /* Set token claims */
claims["iss"] = "overFlow"
claims["uid"] = signinId claims["iat"] = time.Now().Unix()
claims["exp"] = time.Now().Add(time.Hour * 24).Unix() claims["exp"] = time.Now().Add(time.Hour * 24).Unix()
claims["aud"] = "www.overflow.cloud"
claims["sub"] = signinId
/* Sign the token with our secret */ /* Sign the token with our secret */
tokenString, _ := token.SignedString(ofSigningKey) tokenString, _ := token.SignedString([]byte(config.GetString("auth.signingKey")))
var jwtCookie fasthttp.Cookie var jwtCookie fasthttp.Cookie
jwtCookie.SetKey("AuthToken") jwtCookie.SetKey("AuthToken")