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

[GH-380] - Add User Refresh Token Management Functionality to SDK #404

Merged
merged 4 commits into from
May 9, 2024
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/auth0/go-auth0

go 1.21.9
go 1.21

require (
github.com/PuerkitoBio/rehttp v1.4.0
Expand Down
95 changes: 95 additions & 0 deletions management/management.gen.go

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

124 changes: 124 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.

44 changes: 44 additions & 0 deletions management/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,31 @@ type AuthenticationMethodList struct {
Authenticators []*AuthenticationMethod `json:"authenticators,omitempty"`
}

// RefreshTokenList represents a list of user refresh tokens.
type RefreshTokenList struct {
List
Tokens []*RefreshToken `json:"tokens,omitempty"`
}

// RefreshToken represents a refresh token for a user.
type RefreshToken struct {
ID *string `json:"id,omitempty"`
UserID *string `json:"user_id,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
IdleExpiresAt *time.Time `json:"idle_expires_at,omitempty"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
ClientID *string `json:"client_id,omitempty"`
SessionID *string `json:"session_id,omitempty"`
Rotating *bool `json:"rotating,omitempty"`
ResourceServer []*RefreshTokenResourceServer `json:"resource_servers,omitempty"`
}

// RefreshTokenResourceServer represents the resource server associated with a refresh token.
type RefreshTokenResourceServer struct {
Audience *string `json:"audience,omitempty"`
Scopes *string `json:"scopes,omitempty"`
}

// UserManager manages Auth0 User resources.
type UserManager manager

Expand Down Expand Up @@ -724,3 +749,22 @@ func (m *UserManager) DeleteAllAuthenticationMethods(ctx context.Context, userID
err = m.management.Request(ctx, "DELETE", m.management.URI("users", userID, "authentication-methods"), nil, opts...)
return
}

// ListRefreshTokens retrieves details for a user's refresh tokens.
//
// It allows pagination using the provided options. For more information on pagination, refer to:
// https://pkg.go.dev/github.com/auth0/go-auth0/management#hdr-Page_Based_Pagination
//
// See: https://auth0.com/docs/api/management/v2#!/Users/get-refresh-tokens-for-user
func (m *UserManager) ListRefreshTokens(ctx context.Context, userID string, opts ...RequestOption) (r *RefreshTokenList, err error) {
err = m.management.Request(ctx, "GET", m.management.URI("users", userID, "refresh-tokens"), &r, applyListDefaults(opts))
return
}

// DeleteRefreshTokens deletes all refresh tokens for a user.
//
// See: https://auth0.com/docs/api/management/v2#!/Users/delete-refresh-tokens-for-user
func (m *UserManager) DeleteRefreshTokens(ctx context.Context, userID string, opts ...RequestOption) (err error) {
err = m.management.Request(ctx, "DELETE", m.management.URI("users", userID, "refresh-tokens"), nil, opts...)
return
}
Loading