mirror of
https://github.com/twofas/2fas-server.git
synced 2024-12-04 08:09:58 +01:00
feat(pass/sync): use data notifications in push
This commit is contained in:
parent
7bf9bfb906
commit
6ce9d1a7ca
@ -156,14 +156,14 @@ func browserExtensionRequestSync(token string) (RequestSyncResponse, error) {
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func browserExtensionPush(token, body string) (string, error) {
|
||||
func browserExtensionPush(token string, data map[string]string) (string, error) {
|
||||
var resp struct {
|
||||
Response string `json:"response"`
|
||||
}
|
||||
req := struct {
|
||||
Body string `json:"push_body"`
|
||||
Data map[string]string `json:"data"`
|
||||
}{
|
||||
Body: body,
|
||||
Data: data,
|
||||
}
|
||||
|
||||
if err := request("POST", "/browser_extension/sync/push", token, req, &resp); err != nil {
|
||||
|
@ -33,7 +33,7 @@ func TestSyncHappyFlow(t *testing.T) {
|
||||
return
|
||||
}
|
||||
|
||||
pushResp, err := browserExtensionPush(requestSyncResp.BrowserExtensionWaitToken, "body")
|
||||
pushResp, err := browserExtensionPush(requestSyncResp.BrowserExtensionWaitToken, map[string]string{"hello": "world!"})
|
||||
if err != nil {
|
||||
t.Errorf("Error when Browser Extension tried to send push notification: %v", err)
|
||||
return
|
||||
|
@ -39,7 +39,7 @@ func ExtensionRequestSync(syncingApp *Syncing) gin.HandlerFunc {
|
||||
}
|
||||
|
||||
type PushToMobileRequest struct {
|
||||
Body string `json:"push_body"`
|
||||
DataMessage map[string]string `json:"data_message"`
|
||||
}
|
||||
|
||||
func ExtensionRequestPush(syncingApp *Syncing) gin.HandlerFunc {
|
||||
@ -64,7 +64,7 @@ func ExtensionRequestPush(syncingApp *Syncing) gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := syncingApp.SendPush(gCtx, fcmToken, req.Body)
|
||||
resp, err := syncingApp.SendPush(gCtx, fcmToken, req.DataMessage)
|
||||
if err != nil {
|
||||
log.Errorf("Failed to send push message: %v", err)
|
||||
gCtx.Status(http.StatusInternalServerError)
|
||||
|
@ -183,16 +183,11 @@ func (s *Syncing) RequestSync(ctx *gin.Context, token string) (RequestSyncRespon
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *Syncing) SendPush(ctx *gin.Context, token string, body string) (fcm.Response, error) {
|
||||
func (s *Syncing) SendPush(ctx *gin.Context, token string, body map[string]string) (fcm.Response, error) {
|
||||
msg := &messaging.Message{
|
||||
Token: token,
|
||||
Android: &messaging.AndroidConfig{
|
||||
Notification: &messaging.AndroidNotification{
|
||||
Title: "2pass push request",
|
||||
},
|
||||
Data: map[string]string{
|
||||
"data": body,
|
||||
},
|
||||
Data: body,
|
||||
},
|
||||
}
|
||||
return s.fcmClient.Send(ctx, msg)
|
||||
|
Loading…
Reference in New Issue
Block a user