Skip to content

Commit

Permalink
add unregister GCM function
Browse files Browse the repository at this point in the history
  • Loading branch information
John Newman committed Jun 28, 2024
1 parent 5eec7f5 commit 0bd5df3
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions gcm.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,28 @@ func RegisterGCM(ctx context.Context, authorizationEntity string, creds GCMCrede
AppID: appID,
}, nil
}

func UnregisterGCM(ctx context.Context, authorizationEntity string, creds GCMCredentials, appID string) error {
values := url.Values{}
values.Set("app", "org.chromium.linux")
values.Set("scope", "GCM")
values.Set("X-scope", "GCM")
values.Set("X-subtype", appID)
values.Set("device", fmt.Sprint(creds.AndroidID))
values.Set("gmsv", strings.Split(chromeVersion, ".")[0])
values.Set("sender", authorizationEntity)
values.Set("delete", "true")
res, err := postRequest(ctx, registerURL, strings.NewReader(values.Encode()), func(header *http.Header) {
header.Set("Content-Type", "application/x-www-form-urlencoded")
header.Set("Authorization", fmt.Sprintf("AidLogin %d:%d", creds.AndroidID, creds.SecurityToken))
})
if err != nil {
return errors.Wrap(err, "failed to unregister with GCM")
}

if res.StatusCode != http.StatusOK {
return errors.New("failed to unregister with GCM")
}

return nil
}

0 comments on commit 0bd5df3

Please sign in to comment.