Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

Add more MFA endpoints #110

Closed
wants to merge 4 commits into from
Closed

Add more MFA endpoints #110

wants to merge 4 commits into from

Conversation

Serjlee
Copy link

@Serjlee Serjlee commented Apr 30, 2020

Because of some custom integration of MFA, we needed a few more Management API endpoints not yet exposed by this library:

Let me know if I need to tweak something in order to merge!

Copy link
Contributor

@alexkappa alexkappa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for submitting this @Serjlee, I made some mostly aesthetic suggestions as the code seems pretty good.

Can we perhaps add some tests that verify this new functionality?

management/grant.go Outdated Show resolved Hide resolved
management/guardian.go Outdated Show resolved Hide resolved
management/user.go Outdated Show resolved Hide resolved
management/user.go Outdated Show resolved Hide resolved
Copy link
Contributor

@alexkappa alexkappa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Serjlee please let me know if you plan to accommodate the review comments.

@Serjlee
Copy link
Author

Serjlee commented Nov 11, 2020

Hey @alexkappa! I'm back from the dead, I'll address your suggestions in a bit

@Serjlee
Copy link
Author

Serjlee commented Nov 11, 2020

@alexkappa done: I took the chance to squash my changes since I had to rebase to handle the way requests are now built

Copy link
Contributor

@lambdalisue lambdalisue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi. Your initial version was for v4 thus I've made quite a similar PR for v5 already at #157

// Delete an enrollment
//
// See: https://auth0.com/docs/api/management/v2#!/Guardian/delete_enrollments_by_id
func (m *MultiFactorManager) Delete(id string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to add EnrollmentManager here while the API is for an enrollment rather than a factor.

ref: https://github.com/go-auth0/auth0/pull/157/files#diff-e2b523a5aacf304cdcd66ffc8c82c95a9deac4f83af0eb75380fecf23a57a8bfR105

management/user.go Outdated Show resolved Hide resolved
@Serjlee
Copy link
Author

Serjlee commented Nov 16, 2020

@lambdalisue introducing an EnrollmentManager sounds like a good idea, but at this point I wouldn't mind closing this PR in favour of yours since they would became kinda identical.

@alexkappa having either PR merged is ok for me: let us know what to do!

@lambdalisue
Copy link
Contributor

lambdalisue commented Nov 16, 2020

@lambdalisue introducing an EnrollmentManager sounds like a good idea, but at this point I wouldn't mind closing this PR in favour of yours since they would became kinda identical.

Note that mine does not include ListAuthenticators while it's not documented yet. I use the following code to access that endpoint in my production code rather than the library code.

// https://community.auth0.com/t/when-will-api-v2-users-userid-authenticators-be-documented/52722
type authenticator struct {
	ID         *string    `json:"id"`
	Type       *string    `json:"type"`
	Confirmed  *bool      `json:"confirmed"`
	Name       *string    `json:"name,omitempty"`
	CreatedAt  time.Time  `json:"created_at"`
	EnrolledAt *time.Time `json:"enrolled_at,omitempty"`
	LastAuthAt *time.Time `json:"last_auth_at,omitempty"`
	LinkID     *string    `json:"link_id,omitempty"`
}

func getUserAuthenticators(auth0UserID string, opts ...management.RequestOption) (ators []*authenticator, err error) {
	err = m.Request(
		"GET",
		m.URI("users", auth0UserID, "authenticators"),
		&ators,
		opts...,
	)
	return
}

I'll add an equivalent function to my PR if you need that function 👍 Let me know.

@Serjlee
Copy link
Author

Serjlee commented Nov 16, 2020

I thought of exposing it in the library after receiving this reassuring reply from Auth0:

I am not quite sure why it is not documented. However, I confirmed with engineering that if it is safe to use this endpoint. They confirmed that is fine and there are couple of other customers using this endpoint.

(but since in v5 it's possible to build requests from outside the package, I'm fine even without it)

//
// It's an undocumented API, see: https://community.auth0.com/t/when-will-api-v2-users-userid-authenticators-be-documented/52722
func (m *UserManager) ListAuthenticators(id string) (enrols []*UserAuthenticator, err error) {
err = m.Request("POST", m.URI("users", id, "authenticators"), &enrols)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello and thanks for making these additions! Just wanted to pop by and make a quick comment. Using POST for the request in ListAuthenticators gave me a 404, but using GET works. I think we might need to use GET instead (it's probably the same for Enrollments as well).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes, thanks, That's why committing stuff late at night is a terrible idea.

@lambdalisue
Copy link
Contributor

@alexkappa So what should we do next? Close this PR and move to #157 or continue here? Let us know.

@Serjlee
Copy link
Author

Serjlee commented Feb 1, 2021

@lambdalisue's I'm closing this PR in favour of yours since you are definitely keeping a keener eye on this

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants