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

Add Support for Token Exchange Profile with TokenExchangeProfileManager #478

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
66 changes: 66 additions & 0 deletions management/management.gen.go

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

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

4 changes: 4 additions & 0 deletions management/management.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ type Management struct {
// EncryptionKey manages Auth0 Encryption Keys.
EncryptionKey *EncryptionKeyManager

// TokenExchangeProfile manages Auth0 Token Exchange Profiles.
TokenExchangeProfile *TokenExchangeProfileManager

url *url.URL
basePath string
userAgent string
Expand Down Expand Up @@ -219,6 +222,7 @@ func New(domain string, options ...Option) (*Management, error) {
m.Ticket = (*TicketManager)(&m.common)
m.User = (*UserManager)(&m.common)
m.SelfServiceProfile = (*SelfServiceProfileManager)(&m.common)
m.TokenExchangeProfile = (*TokenExchangeProfileManager)(&m.common)
m.Form = (*FormManager)(&m.common)
m.Flow = &FlowManager{
management: m,
Expand Down
98 changes: 98 additions & 0 deletions management/token_exchange_profiles.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package management

import (
"context"
"encoding/json"
)

// TokenExchangeProfile represents a token exchange profile.
type TokenExchangeProfile struct {
// ID is the unique identifier of the token exchange profile.
ID *string `json:"id,omitempty"`
// Name is the name of the token exchange profile.
Name *string `json:"name,omitempty"`
// SubjectTokenType is the type of the subject token.
SubjectTokenType *string `json:"subject_token_type,omitempty"`
// ActionID is the identifier of the action.
ActionID *string `json:"action_id,omitempty"`
// Type is the type of the token exchange profile.
Type *string `json:"type,omitempty"`
// CreatedAt is the date and time when the token exchange profile was created.
CreatedAt *string `json:"created_at,omitempty"`
// UpdatedAt is the date and time when the token exchange profile was last updated.
UpdatedAt *string `json:"updated_at,omitempty"`
}

// TokenExchangeProfileList is a list of TokenExchangeProfiles.
type TokenExchangeProfileList struct {
List
TokenExchangeProfiles []*TokenExchangeProfile `json:"token_exchange_profiles"`
}

// MarshalJSON implements the json.Marshaler interface for the TokenExchangeProfile type.
func (t *TokenExchangeProfile) MarshalJSON() ([]byte, error) {
type TokenExchangeProfileSubset struct {
Name *string `json:"name,omitempty"`
SubjectTokenType *string `json:"subject_token_type,omitempty"`
ActionID *string `json:"action_id,omitempty"`
Type *string `json:"type,omitempty"`
}

return json.Marshal(&TokenExchangeProfileSubset{
Name: t.Name,
SubjectTokenType: t.SubjectTokenType,
ActionID: t.ActionID,
Type: t.Type,
})
}

func (t *TokenExchangeProfile) cleanForPatch() *TokenExchangeProfile {
return &TokenExchangeProfile{
Name: t.Name,
SubjectTokenType: t.SubjectTokenType,
}
}

// TokenExchangeProfileManager manages Auth0 Token Exchange Profile resources.
type TokenExchangeProfileManager manager

// Create a new token exchange profile.
//
// See: https://auth0.com/docs/api/management/v2#!/token-exchange-profiles/post_token_exchange_profile
func (m *TokenExchangeProfileManager) Create(ctx context.Context, t *TokenExchangeProfile, opts ...RequestOption) (err error) {
err = m.management.Request(ctx, "POST", m.management.URI("token-exchange-profiles"), t, opts...)
return
}

// List all token exchange profiles.
//
// See: https://auth0.com/docs/api/management/v2#!/token-exchange-profiles/get_token_exchange_profiles
func (m *TokenExchangeProfileManager) List(ctx context.Context, opts ...RequestOption) (t *TokenExchangeProfileList, err error) {
err = m.management.Request(ctx, "GET", m.management.URI("token-exchange-profiles"), &t, applyListCheckpointDefaults(opts))
return
}

// Read a single token exchange profile against the ID.
//
// See: https://auth0.com/docs/api/management/v2#!/token-exchange-profiles/get_token_exchange_profile
func (m *TokenExchangeProfileManager) Read(ctx context.Context, id string, opts ...RequestOption) (t *TokenExchangeProfile, err error) {
err = m.management.Request(ctx, "GET", m.management.URI("token-exchange-profiles", id), &t, opts...)
return
}

// Update an existing token exchange profile against the ID.
//
// See: https://auth0.com/docs/api/management/v2#!/token-exchange-profiles/patch_token_exchange_profile
func (m *TokenExchangeProfileManager) Update(ctx context.Context, id string, t *TokenExchangeProfile, opts ...RequestOption) (err error) {
t.cleanForPatch()
err = m.management.Request(ctx, "PATCH", m.management.URI("token-exchange-profiles", id), t, opts...)
return
}

// Delete an existing token exchange profile against the ID.
//
// See: https://auth0.com/docs/api/management/v2#!/token-exchange-profiles/delete_token_exchange_profile
func (m *TokenExchangeProfileManager) Delete(ctx context.Context, id string, opts ...RequestOption) (err error) {
err = m.management.Request(ctx, "DELETE", m.management.URI("token-exchange-profiles", id), nil, opts...)
return
}
Loading
Loading