diff --git a/README.md b/README.md
index c9cccc3..916688c 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ Request for Register
```xml
- token-from-distributer-regisration
+ pubic-token
```
@@ -26,7 +26,7 @@ on success:
```xml
- https://an-endpoint-for-application-server.localhost/UP?token=public-token
+ https://an-endpoint-for-application-server.localhost/UP?token=endpoint-token
```
@@ -49,7 +49,7 @@ For the push notification it-self the origin `` is used with following
```xml
- token-from-distributer-regisration
+ public-token
Here is the Notification content
```
diff --git a/distributor/xmpp.go b/distributor/xmpp.go
index 0e50e78..065238c 100644
--- a/distributor/xmpp.go
+++ b/distributor/xmpp.go
@@ -88,16 +88,16 @@ func (s *XMPPService) message(msgHead stanza.Message, t xmlstream.TokenReadEncod
return nil
}
- if msg.Body == "" || msg.Token == "" {
+ if msg.Body == "" || msg.PublicToken == "" {
log.Infof("empty: %v", msgHead)
return nil
}
logger = logger.WithFields(map[string]interface{}{
- "publicToken": msg.Token,
+ "publicToken": msg.PublicToken,
"content": msg.Body,
})
- conn := s.store.GetConnectionbyPublic(msg.Token)
+ conn := s.store.GetConnectionbyPublic(msg.PublicToken)
if conn == nil {
logger.Warnf("no appID and appToken found for publicToken")
}
diff --git a/gateway/token.go b/gateway/token.go
index 563c18c..c809664 100644
--- a/gateway/token.go
+++ b/gateway/token.go
@@ -11,27 +11,27 @@ type JWTSecret string
// JWTToken data field
type JWTToken struct {
jwt.StandardClaims
- Token string `json:"token"`
- JID string `json:"jid"`
+ PublicToken string `json:"token"`
+ JID string `json:"jid"`
}
-// Generate an jwt token by token and jid
-func (s JWTSecret) Generate(jid jid.JID, token string) (string, error) {
+// Generate an endpoint token by public token and jid
+func (s JWTSecret) Generate(jid jid.JID, publicToken string) (string, error) {
jwtToken := JWTToken{
- Token: token,
- JID: jid.String(),
+ PublicToken: publicToken,
+ JID: jid.String(),
}
claim := jwt.NewWithClaims(jwt.SigningMethodHS512, jwtToken)
- t, err := claim.SignedString([]byte(s))
+ endpointToken, err := claim.SignedString([]byte(s))
if err != nil {
return "", err
}
- return t, nil
+ return endpointToken, nil
}
-// Read token to token and jid
-func (s JWTSecret) Read(jwtToken string) (jid.JID, string, error) {
- token, err := jwt.ParseWithClaims(jwtToken, &JWTToken{}, func(token *jwt.Token) (interface{}, error) {
+// Read endpoint token to public token and jid
+func (s JWTSecret) Read(endpointToken string) (jid.JID, string, error) {
+ token, err := jwt.ParseWithClaims(endpointToken, &JWTToken{}, func(token *jwt.Token) (interface{}, error) {
return []byte(s), nil
})
if err != nil {
@@ -45,5 +45,5 @@ func (s JWTSecret) Read(jwtToken string) (jid.JID, string, error) {
if err != nil {
return jid.JID{}, "", err
}
- return addr, claims.Token, nil
+ return addr, claims.PublicToken, nil
}
diff --git a/gateway/web_post.go b/gateway/web_post.go
index 31bacd0..954346d 100644
--- a/gateway/web_post.go
+++ b/gateway/web_post.go
@@ -1,16 +1,17 @@
package main
import (
- "github.com/gin-gonic/gin"
"io/ioutil"
"net/http"
+ "github.com/gin-gonic/gin"
+
"dev.sum7.eu/genofire/golang-lib/web"
)
func Post(r *gin.Engine, ws *web.Service, xmpp *XMPPService, jwtsecret JWTSecret) {
r.POST("/UP", func(c *gin.Context) {
- to, token, err := jwtsecret.Read(c.Query("token"))
+ to, publicToken, err := jwtsecret.Read(c.Query("token"))
if err != nil {
c.JSON(http.StatusUnauthorized, web.HTTPError{
Message: "jwt token unauthoried - or not given",
@@ -27,7 +28,7 @@ func Post(r *gin.Engine, ws *web.Service, xmpp *XMPPService, jwtsecret JWTSecret
return
}
content := string(b)
- if err := xmpp.SendMessage(to, token, content); err != nil {
+ if err := xmpp.SendMessage(to, publicToken, content); err != nil {
c.JSON(http.StatusNotFound, web.HTTPError{
Message: "unable to forward to xmpp",
Error: err.Error(),
diff --git a/gateway/xmpp.go b/gateway/xmpp.go
index f2d44a9..03a387f 100644
--- a/gateway/xmpp.go
+++ b/gateway/xmpp.go
@@ -86,19 +86,19 @@ func (s *XMPPService) handleRegister(iq stanza.IQ, t xmlstream.TokenReadEncoder,
reply.Register.Error = &messages.ErrorData{Body: "unable decode"}
return nil
}
- token := tokenData.Body
- if token == "" {
- log.Warnf("no token found: %v", token)
+ publicToken := tokenData.Body
+ if publicToken == "" {
+ log.Warnf("no token found: %v", publicToken)
reply.Register.Error = &messages.ErrorData{Body: "no token"}
return nil
}
- jwt, err := s.JWTSecret.Generate(iq.From, token)
+ endpointToken, err := s.JWTSecret.Generate(iq.From, publicToken)
if err != nil {
- log.Errorf("unable jwt generation: %v", err)
- reply.Register.Error = &messages.ErrorData{Body: "jwt error on gateway"}
+ log.Errorf("unable entpointToken generation: %v", err)
+ reply.Register.Error = &messages.ErrorData{Body: "endpointToken error on gateway"}
return nil
}
- endpoint := s.EndpointURL + "/UP?token=" + jwt
+ endpoint := s.EndpointURL + "/UP?token=" + endpointToken
reply.IQ.Type = stanza.ResultIQ
reply.Register.Endpoint = &messages.EndpointData{Body: endpoint}
log.Debugf("generate respone: %v", endpoint)
@@ -141,10 +141,10 @@ func (s *XMPPService) handleDisco(iq stanza.IQ, t xmlstream.TokenReadEncoder, st
}
// SendMessage of an UP Notification
-func (s *XMPPService) SendMessage(to jid.JID, token, content string) error {
+func (s *XMPPService) SendMessage(to jid.JID, publicToken, content string) error {
log.WithFields(map[string]interface{}{
- "to": to.String(),
- "token": token,
+ "to": to.String(),
+ "publicToken": publicToken,
}).Debug("forward message to xmpp")
return s.session.Encode(context.TODO(), messages.Message{
Message: stanza.Message{
@@ -153,7 +153,7 @@ func (s *XMPPService) SendMessage(to jid.JID, token, content string) error {
// Type: stanza.ChatMessage,
Type: stanza.NormalMessage,
},
- Token: token,
- Body: content,
+ PublicToken: publicToken,
+ Body: content,
})
}
diff --git a/messages/main.go b/messages/main.go
index 5327c36..9724bde 100644
--- a/messages/main.go
+++ b/messages/main.go
@@ -25,6 +25,7 @@ type RegisterIQ struct {
} `xml:"register"`
}
+// TokenData transport the public token from distributor to gateway
type TokenData struct {
XMLName xml.Name `xml:"token"`
Body string `xml:",chardata"`
@@ -49,7 +50,7 @@ type UnregisterIQ struct {
// Unregister without stanza
type Unregister struct {
XMLName xml.Name `xml:"unifiedpush.org unregister"`
- // set
+ // set - public token
Token string `xml:"token,omitempty"`
// result
Success *string `xml:"success,omitempty"`
@@ -60,12 +61,12 @@ type Unregister struct {
// Message of push notification - with stanza
type Message struct {
stanza.Message
- Token string `xml:"subject"`
- Body string `xml:"body"`
+ PublicToken string `xml:"subject"`
+ Body string `xml:"body"`
}
// MessageBody of push notification - without stanza
type MessageBody struct {
- Token string `xml:"subject"`
- Body string `xml:"body"`
+ PublicToken string `xml:"subject"`
+ Body string `xml:"body"`
}