Skip to content

Commit

Permalink
Add support for APNS and FCM endpoints for Direct mode Guardian
Browse files Browse the repository at this point in the history
  • Loading branch information
lochiiconnectivity committed Mar 15, 2023
1 parent de0ad5d commit 45bfaaa
Show file tree
Hide file tree
Showing 7 changed files with 346 additions and 0 deletions.
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...)
}

// APNS 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
}

// UpdateAPNS 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...)
}

// UpdateFCM 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
44 changes: 44 additions & 0 deletions management/guardian_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package management

import (
"io/ioutil"
"net/http"
"testing"

Expand Down Expand Up @@ -262,6 +263,49 @@ 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 := ioutil.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 @@
MIIQKQIBAzCCD+8GCSqGSIb3DQEHAaCCD+AEgg/cMIIP2DCCBgcGCSqGSIb3DQEHBqCCBfgwggX0AgEAMIIF7QYJKoZIhvcNAQcBMBwGCiqGSIb3DQEMAQYwDgQIeUVaAl1gaYgCAggAgIIFwBOT0coFU8zbBLjONlpmM+m1VdLW5Bnx9f4bapz5ca/nXTHFKtNIQ5Aq4XKb1XOUGCFAtwy2VJHOVPA9489+OAUXTEYt/h4gWzdwgPWkH9mVmEuxbpRZmX/KpUEm9XqWKCAL67oz+HIKLA5Ixvq+QTgQ09En+ZWy2sGE40WRIfVaamSaYm1VPzeu8hVrqomyTEvajP4X2ynOyrtbZKs6KKFR2taQOnMs7WMR9GpTbZ/J+45DgD91n7b7wztIFTAWrIVu6DGvTyi9ZtPgKulrIYVpwGrbF9RmcufiuPRKZsRronc15t5nbZA59qjWi4QAXF2G0nicuAaiS80dUf3LB2wofQOXUVM8uluqD7xBp46Ej9vUYXF1Es8UKCPrWgCEjTp8BusubUsJBkglMan1yHkZp/Ma7uaueeGM2ziIcmslhyAm6hQRfmSTm842RfdibzTTEEcsX7uISFmtm2u40KLazG9riIc7Uo6UPhAn/5xF8pEI3EW7gkD7iY/1+GeWY8rzyQe6L1HpGW7a9ZoDAvWnNEWC3kdv+rggunD927BlOitXqBojKWZ5B1SGHR5k0wvTsmrdlQjZYSgAG4QppetWdGruDa8XHQvZSj0g6IDeMPnGI31w4+2BuE9AQ4awVuP5hrsC2+D0G+qmyXtCpETx2bwG3xgzw9/pFAEziAva2gg9d4+jwh2ThpV0Q/9lSNhjo7uAXMemaue4qTV4P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2DQKkW9ciRGjfHm4ToLPZdix4JLFIW921vLRiAftb5SLexEPfLX8JgJzOlTwNaShuHKFnpSTASiql5vTb8275daZd0GtgiNabBSg5wuyl3O0o6/p4HocIE0n9Tl0SuIpK93KRgcY+jmv/heJUE/oozzHofHfcnHuBCX/b6EleJUfE5qwn4x8ZQHoG2ExYCGOC8z1z9JqaErlsmX8+VVGlG2ZwxAzElMCMGCSqGSIb3DQEJFTEWBBRnKoJl8ZTYC6YMaYN7sl++Br83tTAxMCEwCQYFKw4DAhoFAAQURJ8aeDIQ6DA8wvJMm02M22xRxUQECC/YpLYbMNcSAgIIAA==
Loading

0 comments on commit 45bfaaa

Please sign in to comment.