oliveroneill / exponent-server-sdk-golang

Exponent push notification go library
MIT License
67 stars 42 forks source link

Got “x.509 certificate signed by unknown authority” when the server tried to send Expo notifications #11

Closed byron1st closed 4 years ago

byron1st commented 4 years ago

Hi, I have developed the server written in Go and using this library to send push notifications to my React Native app.

I have two same server sets, one is for the test and the other is for the production. In the test, push notifications works well as intended. I got push notifications successfully.

However, when I updated the production server, I got "x.509 certificate signed by unknown authority" error message when I tried to send notifications to the Expo Push Notification server.

First, I suspected that my expo push token had been corrupted, but the push token worked well when I tested it using Expo push notifications tool.

I am not sure where to look for a solution. If you give me some hints such as from where should I investigate my code/server/settings, it will be great helpful.

The following codes are around the only place that the error can occur.

import (
    expo "github.com/oliveroneill/exponent-server-sdk-golang/sdk"
    "github.com/pkg/errors"
)

type Client struct {
    PushClient *expo.PushClient
}

func NewClient() *Client {
    client := expo.NewPushClient(nil)

    return &Client{PushClient: client}
}

func (c *Client) PushNotifications(deviceKeys []string, title string, body string) (error, map[string]string) {
    messages := make([]expo.PushMessage, 0)
    for _, deviceKey := range deviceKeys {
        pushToken, err := expo.NewExponentPushToken(deviceKey)
        if err != nil {
            continue
        }

        messages = append(messages, expo.PushMessage{
            To:        pushToken,
            Body:      body,
            Data:      nil,
            Sound:     "default",
            Title:     title,
            Priority:  expo.DefaultPriority,
            ChannelID: "default",
        })
    }

    // This is only place the error can occur
    // PublishMultiple function is a part of the Expo SDK
    responses, err := c.PushClient.PublishMultiple(messages)
    if err != nil {
        return errors.WithStack(err), nil
    }

    sentErrors := make(map[string]string)
    for index, response := range responses {
        err := response.ValidateResponse()
        if err != nil && index >= len(deviceKeys) {
            sentErrors[deviceKeys[index]] = err.Error()
        }
    }

    return nil, sentErrors
}

I don't think this is the problem of the library, so this is a just question rather than an "issue". So, if you think this question is not appropriate in this "issue" section, just close it.

Thanks!

byron1st commented 4 years ago

Sorry, it turned out that my server configuration had problem. Not the problem or issue of your library. So I close the issue now.