ing
This commit is contained in:
parent
8a8f7453e6
commit
55016583d4
|
@ -9,3 +9,5 @@ import:
|
||||||
- server
|
- server
|
||||||
- package: github.com/dgrijalva/jwt-go
|
- package: github.com/dgrijalva/jwt-go
|
||||||
version: v3.1.0
|
version: v3.1.0
|
||||||
|
- package: github.com/satori/go.uuid
|
||||||
|
version: v1.2.0
|
||||||
|
|
|
@ -5,8 +5,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
|
"github.com/satori/go.uuid"
|
||||||
|
|
||||||
"git.loafle.net/commons_go/logging"
|
"git.loafle.net/commons_go/logging"
|
||||||
cwf "git.loafle.net/commons_go/websocket_fasthttp"
|
cwf "git.loafle.net/commons_go/websocket_fasthttp"
|
||||||
|
oogw "git.loafle.net/overflow/overflow_gateway_websocket"
|
||||||
"git.loafle.net/overflow/overflow_gateway_websocket/rpc"
|
"git.loafle.net/overflow/overflow_gateway_websocket/rpc"
|
||||||
jwt "github.com/dgrijalva/jwt-go"
|
jwt "github.com/dgrijalva/jwt-go"
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
|
@ -56,10 +59,8 @@ func (sh *GatewayRPCHandlers) Init(serverCTX cwf.ServerContext) error {
|
||||||
func (sh *GatewayRPCHandlers) Handshake(socketCTX cwf.SocketContext, ctx *fasthttp.RequestCtx) (id string, extensionsHeader *fasthttp.ResponseHeader) {
|
func (sh *GatewayRPCHandlers) Handshake(socketCTX cwf.SocketContext, ctx *fasthttp.RequestCtx) (id string, extensionsHeader *fasthttp.ResponseHeader) {
|
||||||
var ok bool
|
var ok bool
|
||||||
// tokenString := string(ctx.Request.Header.Cookie("authToken"))
|
// tokenString := string(ctx.Request.Header.Cookie("authToken"))
|
||||||
tokenString := string(ctx.QueryArgs().Peek("authToken"))
|
|
||||||
// log.Printf("authToken: %s \n", tokenString)
|
|
||||||
// log.Printf("authToken: %s \n", string(ctx.QueryArgs().Pe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2FmbGUuY29tIn0.Umjy3_qvFe4A2wv62r7s2XbqnX_P22HIvAJfx8azM-lejRzYu0wOx9T1UFjRPFzEJO8fEztG1sq3FN5g2097tS6-kbrV5TvB5HclCsK7H384k9CrZEFSgImT-_7yotcPvKKydzvSzLznlbgglr1QwHKH-5JmqyMlxaaYmARmjPHY_tt6NByfeXHEwIL0rh-4TMbx4QOrsBlOHbaRKQqxy8CLwDN2c8-eoEvu1TEIaCxR9rqPrHgsy__1WOY_QY1MdyPzmToXQiwhPyy0hU3jlpf7G9GQOgIEoBD-yrk_WbsFihB2S4uS0TsyopOnEtfSYT5sItnfzCikjNFAaKac39mhW9rPZ-XbxEHK_UYpiCIBtdmiP2ObBCS0FUT2won0V5l4pEw7MTkDehZJptGl45Xrb-ELn-T1lOE6LWuQnZz2sPu2_UHJBcxhPvX6F7cUA3Jm0UGKytq-QOyrUCoiF9YiruDrCXiUkwTQocFwhAGYYeUqQx0KybqLkmn9mkB6zfdyIbY3rk0ep0Kwgp3HTcQR2_6SVkLNAihBpPvZsE5HyVB3hWrOjq-6p0KLj4jfykykj0pA9hNs9qDp5Xb7MR0vRJo__qgvCEe1CiKWwTJY0dXiDDwcIZtqL1u_UdiwZg5Q_O-OCX90IgIETHZNiqAOCKp1IuO9BdplxyCEOBw"
|
||||||
|
tokenString := string(ctx.QueryArgs().Peek("authToken"))
|
||||||
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
|
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
|
||||||
// Don't forget to validate the alg is what you expect:
|
// Don't forget to validate the alg is what you expect:
|
||||||
if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok {
|
if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok {
|
||||||
|
@ -80,7 +81,13 @@ func (sh *GatewayRPCHandlers) Handshake(socketCTX cwf.SocketContext, ctx *fastht
|
||||||
return "", nil
|
return "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return claims["sub"].(string), nil
|
userEmail := claims["sub"].(string)
|
||||||
|
sessionID := uuid.NewV4().String()
|
||||||
|
|
||||||
|
socketCTX.SetAttribute(oogw.ClientTypeKey, oogw.MEMBER)
|
||||||
|
socketCTX.SetAttribute(oogw.TargetIDKey, userEmail)
|
||||||
|
|
||||||
|
return sessionID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sh *GatewayRPCHandlers) Validate() {
|
func (sh *GatewayRPCHandlers) Validate() {
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
package webapp
|
package webapp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.loafle.net/commons_go/logging"
|
||||||
|
cwf "git.loafle.net/commons_go/websocket_fasthttp"
|
||||||
"git.loafle.net/commons_go/websocket_fasthttp/websocket"
|
"git.loafle.net/commons_go/websocket_fasthttp/websocket"
|
||||||
|
oogw "git.loafle.net/overflow/overflow_gateway_websocket"
|
||||||
oogws "git.loafle.net/overflow/overflow_gateway_websocket/servlet"
|
oogws "git.loafle.net/overflow/overflow_gateway_websocket/servlet"
|
||||||
oogwsub "git.loafle.net/overflow/overflow_gateway_websocket/subscribe"
|
oogwsub "git.loafle.net/overflow/overflow_gateway_websocket/subscribe"
|
||||||
oos "git.loafle.net/overflow/overflow_subscriber"
|
oos "git.loafle.net/overflow/overflow_subscriber"
|
||||||
|
@ -20,11 +25,40 @@ type SubscriberHandlers struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sh *SubscriberHandlers) OnSubscribe(channel string, message oos.SubscribeMessage) {
|
func (sh *SubscriberHandlers) OnSubscribe(channel string, message oos.SubscribeMessage) {
|
||||||
for _, uid := range message.Targets {
|
switch message.TargetType {
|
||||||
if soc := sh.GetSocket(uid); nil != soc {
|
case oos.MEMBER:
|
||||||
soc.WriteMessage(websocket.TextMessage, message.Message)
|
for _, uid := range message.Targets {
|
||||||
|
sockets := sh.getMemberSockets(uid)
|
||||||
|
if nil == sockets {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, soc := range sockets {
|
||||||
|
soc.WriteMessage(websocket.TextMessage, message.Message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case oos.MEMBER_SESSION:
|
||||||
|
for _, sid := range message.Targets {
|
||||||
|
if soc := sh.GetSocket(sid); nil != soc {
|
||||||
|
soc.WriteMessage(websocket.TextMessage, message.Message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
logging.Logger().Warn(fmt.Sprintf("[WEBAPP] SubscriberHandler: Unknown TargetType %s", message.TargetType))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sh *SubscriberHandlers) getMemberSockets(targetID string) []cwf.Socket {
|
||||||
|
var sockets []cwf.Socket
|
||||||
|
|
||||||
|
for _, socket := range sh.GetSockets() {
|
||||||
|
if socket.Context().GetAttribute(oogw.TargetIDKey).(string) == targetID {
|
||||||
|
sockets = append(sockets, socket)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return sockets
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sh *SubscriberHandlers) Validate() {
|
func (sh *SubscriberHandlers) Validate() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user