Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for APNS and FCM endpoints for Direct mode Guardian #184

Merged
merged 4 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions management/guardian.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ type MultiFactorPushCustomApp struct {
GoogleAppLink *string `json:"google_app_link,omitempty"`
}

// MultiFactorPushDirectAPNS holds the Apple APNS provider configuration.
type MultiFactorPushDirectAPNS struct {
Sandbox *bool `json:"sandbox,omitempty"`
BundleID *string `json:"bundle_id,omitempty"`
P12 *string `json:"p12,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
}

// MultiFactorPushDirectFCM holds the Google FCM provider configuration.
type MultiFactorPushDirectFCM struct {
// FCM Server Key
ServerKey *string `json:"server_key,omitempty"`
}

// MultiFactorProviderTwilio is used for Twilio MultiFactor Authentication.
type MultiFactorProviderTwilio struct {
// From number
Expand Down Expand Up @@ -355,6 +369,27 @@ func (m *MultiFactorPush) UpdateCustomApp(a *MultiFactorPushCustomApp, opts ...R
return m.Request("PATCH", m.URI("prompts", "mfa-push"), a, opts...)
}

// DirectAPNS returns the Apple APNS provider configuration for direct mode.
// See: https://auth0.com/docs/api/management/v2#!/Guardian/get_apns
func (m *MultiFactorPush) DirectAPNS(opts ...RequestOption) (s *MultiFactorPushDirectAPNS, err error) {
err = m.Request("GET", m.URI("guardian", "factors", "push-notification", "providers", "apns"), &s, opts...)
return
}

// UpdateDirectAPNS updates the Apple APNS provider configuration for direct mode.
//
// See: https://auth0.com/docs/api/management/v2#!/Guardian/patch_apns
func (m *MultiFactorPush) UpdateDirectAPNS(sc *MultiFactorPushDirectAPNS, opts ...RequestOption) error {
return m.Request("PUT", m.URI("guardian", "factors", "push-notification", "providers", "apns"), sc, opts...)
}

// UpdateDirectFCM updates the Google FCM provider configuration for direct mode.
//
// See: https://auth0.com/docs/api/management/v2#!/Guardian/patch_fcm
func (m *MultiFactorPush) UpdateDirectFCM(sc *MultiFactorPushDirectFCM, opts ...RequestOption) error {
return m.Request("PUT", m.URI("guardian", "factors", "push-notification", "providers", "fcm"), sc, opts...)
}

// AmazonSNS returns the Amazon Web Services (AWS) Simple Notification Service
// (SNS) provider configuration.
//
Expand Down
43 changes: 43 additions & 0 deletions management/guardian_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package management

import (
"net/http"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -262,6 +263,48 @@ func TestGuardian(t *testing.T) {
assert.Equal(t, expectedCustomApp.GetAppleAppLink(), actualCustomApp.GetAppleAppLink())
assert.Equal(t, expectedCustomApp.GetGoogleAppLink(), actualCustomApp.GetGoogleAppLink())
})

t.Run("DirectAPNS", func(t *testing.T) {
configureHTTPTestRecordings(t)

_, err := api.Guardian.MultiFactor.Push.DirectAPNS()
assert.NoError(t, err)

// Cannot reflect back the payload we initially received
// as it is incompatible

// Read the p12 from file
expectedP12, err := os.ReadFile("../test/data/apns.p12")
assert.NoError(t, err)

expectedDirectAPNS := &MultiFactorPushDirectAPNS{
Sandbox: auth0.Bool(false),
BundleID: auth0.String("com.my.app"),
P12: auth0.String(string(expectedP12)),
}
err = api.Guardian.MultiFactor.Push.UpdateDirectAPNS(expectedDirectAPNS)
assert.NoError(t, err)

actualDirectAPNS, err := api.Guardian.MultiFactor.Push.DirectAPNS()
assert.NoError(t, err)
assert.Equal(t, expectedDirectAPNS.GetSandbox(), actualDirectAPNS.GetSandbox())
assert.Equal(t, expectedDirectAPNS.GetBundleID(), actualDirectAPNS.GetBundleID())
// Cannot test enabled parameter as we cannot send it
})

t.Run("DirectFCM", func(t *testing.T) {
configureHTTPTestRecordings(t)

// This is a write only property

err := error(nil)

expectedDirectFCM := &MultiFactorPushDirectFCM{
ServerKey: auth0.String("abc123"),
}
err = api.Guardian.MultiFactor.Push.UpdateDirectFCM(expectedDirectFCM)
assert.NoError(t, err)
})
})

t.Run("Email Enable", func(t *testing.T) {
Expand Down
50 changes: 50 additions & 0 deletions management/management.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions management/management.gen_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/data/apns.p12
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
MIIPWQIBAzCCDx8GCSqGSIb3DQEHAaCCDxAEgg8MMIIPCDCCBT8GCSqGSIb3DQEHBqCCBTAwggUsAgEAMIIFJQYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQYwDgQIEqASt2nke/cCAggAgIIE+OfXs2QaQi6YCoX8miVklKSBTaRo4H3beDeRdKM9+EunR361uyTPAcMtnxedEBtJcGtV0rXGn5OW70Spux8KW8rj2TW3cMe8qn+6iZyauv+G3VkOGiHdY5BAYRea3oyPwmMEfvLkYLUYxcZip22M8U0rpR9AUy+eVk7RxYSXa9YqIkwRDqkLY1lUhtROxdwpXE5hk+9YqnUYyrQm4rsIVJJT+G8Yqdn950v0bQZnG6VipvHrnUTMotQxZDHOENFeH4PJkRhdbvRpAC7ayTZaSqjbV6BjFnA3hCy/5xHtWQukCEilSySDZ82/l8nnU2f4YGXfoJT03Y4VK/VeVw45bEFZ9NLQ+CF+ZX/eeXUtvvaun9uV2dDH2mgK3mDWmNJNR4Yvr9tZU/WRs45UywQ7G+ZWAqcD7b2rs98qSq7+SDerbQK5RiTQOzs2tyDkuzbbTUq67Mr9bA8qXgSaX1aWHyBqNxEJ5mPPzvci+pW/cD/lPoXTpS25QjHHxmh2DQYXywgAYv8G6hnKvyCdCm/YDguq2OAjjD22n3L/xpsLboUkSm3PVUxyCe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