Ejemplo n.º 1
0
func authWithToken(c *gin.Context, userToken string) error {
	token, err := jwt.Parse(userToken, func(token *jwt.Token) (interface{}, error) {
		if jwt.GetSigningMethod("HS256") != token.Method {
			//TODO: "Invalid signing token algorithm."
			return nil, nil
		}

		//TODO: cache this
		tokenSecretRecord, err := db.NewSystemDbService().FindId("accountSecret", nil)

		if err != nil {
			log.Error("No account secret found", err)
			//we probably do not have such collection. Use a default secret and warn.
			tokenSecretRecord = models.JSON{
				"value": "",
			}
		}

		tokenSecret := tokenSecretRecord["value"].(string)

		return []byte(tokenSecret), nil
	})

	c.Set("token", token)
	c.Set("user", token.Claims["user"])

	return err
}
Ejemplo n.º 2
0
func NewConnection(c *websocket.Conn, g string) RealtimeConnection {
	r := &realtimeConnection{
		conn:      c,
		group:     g,
		processor: NewMessageProcessor(),
	}

	go func() {
		err := r.Listen()

		if err != nil {
			defer r.Close()

			log.Error(err)
			GetConnectionStore().Remove(g, r)
		}
	}()

	return r
}