diff --git a/authentication/mfa.go b/authentication/mfa.go index 7857b7dd..f971eb1c 100644 --- a/authentication/mfa.go +++ b/authentication/mfa.go @@ -136,10 +136,10 @@ func (m *MFA) VerifyWithRecoveryCode(ctx context.Context, body mfa.VerifyWithRec return } -// AddAnAuthenticator Associates or adds a new authenticator for multi-factor authentication (MFA). +// AddAuthenticator Associates or adds a new authenticator for multi-factor authentication (MFA). // // See: https://auth0.com/docs/api/authentication#add-an-authenticator -func (m *MFA) AddAnAuthenticator(ctx context.Context, accessOrMfaToken string, body mfa.AddAnAuthenticatorRequest, opts ...RequestOption) (a *mfa.AddAnAuthenticatorResponse, err error) { +func (m *MFA) AddAuthenticator(ctx context.Context, accessOrMfaToken string, body mfa.AddAuthenticatorRequest, opts ...RequestOption) (a *mfa.AddAuthenticatorResponse, err error) { opts = append(opts, Header("Authorization", "Bearer "+accessOrMfaToken)) missing := []string{} check(&missing, "ClientID", (body.ClientID != "" || m.authentication.clientID != "")) @@ -159,16 +159,16 @@ func (m *MFA) AddAnAuthenticator(ctx context.Context, accessOrMfaToken string, b // ListAuthenticators Returns a list of authenticators associated with your application. // // See: https://auth0.com/docs/api/authentication#list-authenticators -func (m *MFA) ListAuthenticators(ctx context.Context, accessToken string, opts ...RequestOption) (a []mfa.ListAuthenticatorsResponse, err error) { - opts = append(opts, Header("Authorization", "Bearer "+accessToken)) +func (m *MFA) ListAuthenticators(ctx context.Context, accessOrMfaToken string, opts ...RequestOption) (a []mfa.ListAuthenticatorsResponse, err error) { + opts = append(opts, Header("Authorization", "Bearer "+accessOrMfaToken)) err = m.authentication.Request(ctx, "GET", m.authentication.URI("mfa", "authenticators"), nil, &a, opts...) return } -// DeleteAnAuthenticator Deletes an associated authenticator using its ID. +// DeleteAuthenticator Deletes an associated authenticator using its ID. // // See: https://auth0.com/docs/api/authentication#delete-an-authenticator -func (m *MFA) DeleteAnAuthenticator(ctx context.Context, accessToken string, authenticatorID string, opts ...RequestOption) (err error) { +func (m *MFA) DeleteAuthenticator(ctx context.Context, accessToken string, authenticatorID string, opts ...RequestOption) (err error) { opts = append(opts, Header("Authorization", "Bearer "+accessToken)) err = m.authentication.Request(ctx, "DELETE", m.authentication.URI("mfa", "authenticators", authenticatorID), nil, nil, opts...) return diff --git a/authentication/mfa/mfa.go b/authentication/mfa/mfa.go index 9736e58b..ebac461a 100644 --- a/authentication/mfa/mfa.go +++ b/authentication/mfa/mfa.go @@ -61,8 +61,8 @@ type VerifyWithRecoveryCodeResponse struct { RecoveryCode string `json:"recovery_code,omitempty"` } -// AddAnAuthenticatorRequest defines the request body for adding an authenticator. -type AddAnAuthenticatorRequest struct { +// AddAuthenticatorRequest defines the request body for adding an authenticator. +type AddAuthenticatorRequest struct { oauth.ClientAuthentication // The type of authenticators supported by the client. // An array with values "otp" or "oob". @@ -76,8 +76,8 @@ type AddAnAuthenticatorRequest struct { PhoneNumber string `json:"phone_number,omitempty"` } -// AddAnAuthenticatorResponse defines the response when adding an authenticator. -type AddAnAuthenticatorResponse struct { +// AddAuthenticatorResponse defines the response when adding an authenticator. +type AddAuthenticatorResponse struct { // If present, the OOB code that should be presented to the user to verify the authenticator. OOBCode string `json:"oob_code,omitempty"` // If present, a new recovery code that should be presented to the user to store. diff --git a/authentication/mfa_test.go b/authentication/mfa_test.go index c250abe3..ad3d58fc 100644 --- a/authentication/mfa_test.go +++ b/authentication/mfa_test.go @@ -176,7 +176,7 @@ func TestMFAVerifyWithRecoveryCode(t *testing.T) { }) } -func TestMFA_AddAnAuthenticator(t *testing.T) { +func TestMFAAddAuthenticator(t *testing.T) { t.Run("Should require ClientID, AuthenticatorTypes", func(t *testing.T) { auth, err := New( context.Background(), @@ -184,9 +184,9 @@ func TestMFA_AddAnAuthenticator(t *testing.T) { ) require.NoError(t, err) - _, err = auth.MFA.AddAnAuthenticator(context.Background(), + _, err = auth.MFA.AddAuthenticator(context.Background(), "mfa-token", - mfa.AddAnAuthenticatorRequest{}) + mfa.AddAuthenticatorRequest{}) assert.ErrorContains(t, err, "Missing required fields: ClientID, AuthenticatorTypes") }) @@ -194,9 +194,9 @@ func TestMFA_AddAnAuthenticator(t *testing.T) { skipE2E(t) configureHTTPTestRecordings(t, authAPI) - response, err := authAPI.MFA.AddAnAuthenticator(context.Background(), + response, err := authAPI.MFA.AddAuthenticator(context.Background(), "mfa-token", - mfa.AddAnAuthenticatorRequest{ + mfa.AddAuthenticatorRequest{ ClientAuthentication: oauth.ClientAuthentication{ ClientSecret: clientSecret, }, @@ -216,9 +216,9 @@ func TestMFA_AddAnAuthenticator(t *testing.T) { skipE2E(t) configureHTTPTestRecordings(t, authAPI) - response, err := authAPI.MFA.AddAnAuthenticator(context.Background(), + response, err := authAPI.MFA.AddAuthenticator(context.Background(), "mfa-token", - mfa.AddAnAuthenticatorRequest{ + mfa.AddAuthenticatorRequest{ ClientAuthentication: oauth.ClientAuthentication{ ClientSecret: clientSecret, }, @@ -236,9 +236,9 @@ func TestMFA_AddAnAuthenticator(t *testing.T) { skipE2E(t) configureHTTPTestRecordings(t, authAPI) - response, err := authAPI.MFA.AddAnAuthenticator(context.Background(), + response, err := authAPI.MFA.AddAuthenticator(context.Background(), "mfa-token", - mfa.AddAnAuthenticatorRequest{ + mfa.AddAuthenticatorRequest{ ClientAuthentication: oauth.ClientAuthentication{ ClientSecret: clientSecret, }, @@ -252,7 +252,7 @@ func TestMFA_AddAnAuthenticator(t *testing.T) { }) } -func TestMFA_ListAuthenticators(t *testing.T) { +func TestMFAListAuthenticators(t *testing.T) { skipE2E(t) configureHTTPTestRecordings(t, authAPI) @@ -263,17 +263,12 @@ func TestMFA_ListAuthenticators(t *testing.T) { assert.NotEmpty(t, authenticators) } -/*func TestMFA_DeleteAnAuthenticator(t *testing.T) { - - t.Run("Should return no error for a valid request", func(t *testing.T) { - skipE2E(t) - configureHTTPTestRecordings(t, authAPI) - - err := authAPI.MFA.DeleteAnAuthenticator(context.Background(), - "access-token", - "push|dev_BBTKYpxKHOXVBnql") +func TestMFADeleteAuthenticator(t *testing.T) { + skipE2E(t) + configureHTTPTestRecordings(t, authAPI) - require.NoError(t, err) - }) + err := authAPI.MFA.DeleteAuthenticator(context.Background(), + "mfa-token", + "push|dev_BBTKYpxKHOXVBnql") + require.NoError(t, err) } -*/ diff --git a/test/data/recordings/authentication/TestMFA_AddAnAuthenticator/Should_return_response_for_OOB_(Auth0_channel).yaml b/test/data/recordings/authentication/TestMFAAddAuthenticator/Should_return_response_for_OOB_(Auth0_channel).yaml similarity index 100% rename from test/data/recordings/authentication/TestMFA_AddAnAuthenticator/Should_return_response_for_OOB_(Auth0_channel).yaml rename to test/data/recordings/authentication/TestMFAAddAuthenticator/Should_return_response_for_OOB_(Auth0_channel).yaml diff --git a/test/data/recordings/authentication/TestMFA_AddAnAuthenticator/Should_return_response_for_OOB_(SMS_channel).yaml b/test/data/recordings/authentication/TestMFAAddAuthenticator/Should_return_response_for_OOB_(SMS_channel).yaml similarity index 100% rename from test/data/recordings/authentication/TestMFA_AddAnAuthenticator/Should_return_response_for_OOB_(SMS_channel).yaml rename to test/data/recordings/authentication/TestMFAAddAuthenticator/Should_return_response_for_OOB_(SMS_channel).yaml diff --git a/test/data/recordings/authentication/TestMFA_AddAnAuthenticator/Should_return_response_for_OTP.yaml b/test/data/recordings/authentication/TestMFAAddAuthenticator/Should_return_response_for_OTP.yaml similarity index 100% rename from test/data/recordings/authentication/TestMFA_AddAnAuthenticator/Should_return_response_for_OTP.yaml rename to test/data/recordings/authentication/TestMFAAddAuthenticator/Should_return_response_for_OTP.yaml diff --git a/test/data/recordings/authentication/TestMFADeleteAuthenticator.yaml b/test/data/recordings/authentication/TestMFADeleteAuthenticator.yaml new file mode 100644 index 00000000..160fdea1 --- /dev/null +++ b/test/data/recordings/authentication/TestMFADeleteAuthenticator.yaml @@ -0,0 +1,36 @@ +--- +version: 2 +interactions: + - id: 0 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: go-auth0-dev.eu.auth0.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + url: https://go-auth0-dev.eu.auth0.com/mfa/authenticators/push%7Cdev_BBTKYpxKHOXVBnql + method: DELETE + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: 107 + uncompressed: false + body: "" + headers: + Content-Type: + - application/json + status: 204 No Content + code: 204 + duration: 252.26575ms diff --git a/test/data/recordings/authentication/TestMFA_ListAuthenticators.yaml b/test/data/recordings/authentication/TestMFAListAuthenticators.yaml similarity index 100% rename from test/data/recordings/authentication/TestMFA_ListAuthenticators.yaml rename to test/data/recordings/authentication/TestMFAListAuthenticators.yaml