diff --git a/gorush/notification_apns.go b/gorush/notification_apns.go index 014b9d3..5815c34 100644 --- a/gorush/notification_apns.go +++ b/gorush/notification_apns.go @@ -98,7 +98,12 @@ func InitAPNSClient() error { } } - if ext == ".p8" && PushConf.Ios.KeyID != "" && PushConf.Ios.TeamID != "" { + if ext == ".p8" { + if PushConf.Ios.KeyID == "" || PushConf.Ios.TeamID == "" { + msg := "You should provide ios.KeyID and ios.TeamID for P8 token" + LogError.Error(msg) + return errors.New(msg) + } token := &token.Token{ AuthKey: authKey, // KeyID from developer account (Certificates, Identifiers & Profiles -> Keys) diff --git a/gorush/notification_apns_test.go b/gorush/notification_apns_test.go index 083df17..35a0325 100644 --- a/gorush/notification_apns_test.go +++ b/gorush/notification_apns_test.go @@ -609,6 +609,22 @@ func TestAPNSClientInvaildToken(t *testing.T) { PushConf.Ios.KeyType = "p8" err = InitAPNSClient() assert.Error(t, err) + + //empty key-id or team-id + PushConf.Ios.Enabled = true + PushConf.Ios.KeyPath = "../certificate/authkey-valid.p8" + err = InitAPNSClient() + assert.Error(t, err) + + PushConf.Ios.KeyID = "key-id" + PushConf.Ios.TeamID = "" + err = InitAPNSClient() + assert.Error(t, err) + + PushConf.Ios.KeyID = "" + PushConf.Ios.TeamID = "team-id" + err = InitAPNSClient() + assert.Error(t, err) } func TestAPNSClientVaildToken(t *testing.T) { @@ -616,6 +632,8 @@ func TestAPNSClientVaildToken(t *testing.T) { PushConf.Ios.Enabled = true PushConf.Ios.KeyPath = "../certificate/authkey-valid.p8" + PushConf.Ios.KeyID = "key-id" + PushConf.Ios.TeamID = "team-id" err := InitAPNSClient() assert.NoError(t, err) assert.Equal(t, apns2.HostDevelopment, ApnsClient.Host) diff --git a/main.go b/main.go index aa5a274..bee755a 100644 --- a/main.go +++ b/main.go @@ -60,6 +60,8 @@ func main() { flag.StringVar(&opts.Core.PID.Path, "pid", "", "PID file path.") flag.StringVar(&opts.Ios.KeyPath, "i", "", "iOS certificate key file path") flag.StringVar(&opts.Ios.KeyPath, "key", "", "iOS certificate key file path") + flag.StringVar(&opts.Ios.KeyID, "key-id", "", "iOS Key ID for P8 token") + flag.StringVar(&opts.Ios.TeamID, "team-id", "", "iOS Team ID for P8 token") flag.StringVar(&opts.Ios.Password, "P", "", "iOS certificate password for gorush") flag.StringVar(&opts.Ios.Password, "password", "", "iOS certificate password for gorush") flag.StringVar(&opts.Android.APIKey, "k", "", "Android api key configuration for gorush") @@ -111,6 +113,14 @@ func main() { gorush.PushConf.Ios.KeyPath = opts.Ios.KeyPath } + if opts.Ios.KeyID != "" { + gorush.PushConf.Ios.KeyID = opts.Ios.KeyID + } + + if opts.Ios.TeamID != "" { + gorush.PushConf.Ios.TeamID = opts.Ios.TeamID + } + if opts.Ios.Password != "" { gorush.PushConf.Ios.Password = opts.Ios.Password }