JWT
This commit is contained in:
parent
045a75c3c9
commit
3ad163d316
|
@ -9,3 +9,5 @@ import:
|
|||
- package: git.loafle.net/overflow/overflow_api_server
|
||||
subpackages:
|
||||
- golang
|
||||
- package: github.com/dgrijalva/jwt-go
|
||||
version: v3.0.0
|
||||
|
|
|
@ -2,16 +2,21 @@ package member
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.loafle.net/overflow/overflow_server_app/backend"
|
||||
|
||||
"git.loafle.net/overflow/overflow_server_app/server"
|
||||
|
||||
"github.com/valyala/fasthttp"
|
||||
"encoding/json"
|
||||
"log"
|
||||
|
||||
jwt "github.com/dgrijalva/jwt-go"
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
var ofSigningKey = []byte("secret")
|
||||
|
||||
func SignIn(sctx *server.ServerContext, ctx *fasthttp.RequestCtx) {
|
||||
grpcPool := sctx.Value("grpc").(backend.Pool)
|
||||
fmt.Fprintf(ctx, "avail: %d\n", grpcPool.Available())
|
||||
|
@ -36,7 +41,7 @@ func SignIn(sctx *server.ServerContext, ctx *fasthttp.RequestCtx) {
|
|||
|
||||
length := len(webParams)
|
||||
|
||||
if length < 0{
|
||||
if length < 0 {
|
||||
fmt.Println("eeee")
|
||||
}
|
||||
|
||||
|
@ -44,10 +49,31 @@ func SignIn(sctx *server.ServerContext, ctx *fasthttp.RequestCtx) {
|
|||
signinId := jsonMap["signinId"].(string)
|
||||
signinPw := jsonMap["signinPw"].(string)
|
||||
|
||||
|
||||
params := []string{signinId, signinPw}
|
||||
|
||||
r, err := c.Exec("MemberService", "signin", params)
|
||||
if nil != err {
|
||||
fmt.Fprintf(ctx, "%v", err)
|
||||
return
|
||||
}
|
||||
|
||||
token := jwt.New(jwt.SigningMethodRS256)
|
||||
|
||||
/* Create a map to store our claims */
|
||||
claims := token.Claims.(jwt.MapClaims)
|
||||
|
||||
/* Set token claims */
|
||||
|
||||
claims["uid"] = signinId
|
||||
claims["exp"] = time.Now().Add(time.Hour * 24).Unix()
|
||||
|
||||
/* Sign the token with our secret */
|
||||
tokenString, _ := token.SignedString(ofSigningKey)
|
||||
|
||||
var jwtCookie fasthttp.Cookie
|
||||
jwtCookie.SetKey("AuthToken")
|
||||
jwtCookie.SetValue(tokenString)
|
||||
ctx.Response.Header.SetCookie(&jwtCookie)
|
||||
|
||||
//fmt.Fprintf(ctx, "Welcome!!!!: %s\n", r)
|
||||
ctx.SetContentType("application/javascript")
|
||||
|
|
Loading…
Reference in New Issue
Block a user