Skip to content

Commit

Permalink
[GH-380] - Add User Refresh Token Management Functionality to SDK (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
developerkunal authored May 9, 2024
1 parent aa8d96b commit 6dfa129
Show file tree
Hide file tree
Showing 7 changed files with 527 additions and 1 deletion.
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

0 comments on commit 6dfa129

Please sign in to comment.