Skip to content

Commit

Permalink
feat: Support the OAuth application 'redirect_uris' property
Browse files Browse the repository at this point in the history
We enhance the OAuth application response with the new property 'redirect_uris' that will replace
the existing 'callback_url', which is now marked as deprecated. Also we support passing the new
property during the create and update operations
  • Loading branch information
chanioxaris committed Jan 29, 2025
1 parent 670e6d8 commit f312008
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 29 deletions.
35 changes: 19 additions & 16 deletions oauth_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@ package clerk

type OAuthApplication struct {
APIResource
Object string `json:"object"`
ID string `json:"id"`
InstanceID string `json:"instance_id"`
Name string `json:"name"`
ClientID string `json:"client_id"`
ClientSecret *string `json:"client_secret,omitempty"`
Public bool `json:"public"`
Scopes string `json:"scopes"`
CallbackURL string `json:"callback_url"`
DiscoveryURL string `json:"discovery_url"`
AuthorizeURL string `json:"authorize_url"`
TokenFetchURL string `json:"token_fetch_url"`
UserInfoURL string `json:"user_info_url"`
TokenIntrospectionURL string `json:"token_introspection_url"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
Object string `json:"object"`
ID string `json:"id"`
InstanceID string `json:"instance_id"`
Name string `json:"name"`
ClientID string `json:"client_id"`
ClientSecret *string `json:"client_secret,omitempty"`
Public bool `json:"public"`
Scopes string `json:"scopes"`
RedirectURIs []string `json:"redirect_uris"`
DiscoveryURL string `json:"discovery_url"`
AuthorizeURL string `json:"authorize_url"`
TokenFetchURL string `json:"token_fetch_url"`
UserInfoURL string `json:"user_info_url"`
TokenIntrospectionURL string `json:"token_introspection_url"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`

// Deprecated: Use RedirectURIs instead
CallbackURL string `json:"callback_url"`
}

type OAuthApplicationList struct {
Expand Down
18 changes: 12 additions & 6 deletions oauthapplication/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ func (c *Client) List(ctx context.Context, params *ListParams) (*clerk.OAuthAppl

type CreateParams struct {
clerk.APIParams
Name string `json:"name"`
Name string `json:"name"`
RedirectURIs []string `json:"redirect_uris,omitempty"`
Scopes *string `json:"scopes,omitempty"`
Public *bool `json:"public,omitempty"`

// Deprecated: Use RedirectURIs instead
CallbackURL *string `json:"callback_url,omitempty"`
Scopes *string `json:"scopes,omitempty"`
Public *bool `json:"public,omitempty"`
}

// Create creates a new OAuth application with the given parameters.
Expand All @@ -72,10 +75,13 @@ func (c *Client) Create(ctx context.Context, params *CreateParams) (*clerk.OAuth

type UpdateParams struct {
clerk.APIParams
Name *string `json:"name,omitempty"`
Name *string `json:"name,omitempty"`
RedirectURIs []string `json:"redirect_uris,omitempty"`
Scopes *string `json:"scopes,omitempty"`
Public *bool `json:"public,omitempty"`

// Deprecated: Use RedirectURIs instead
CallbackURL *string `json:"callback_url,omitempty"`
Scopes *string `json:"scopes,omitempty"`
Public *bool `json:"public,omitempty"`
}

// Update updates an existing OAuth application.
Expand Down
16 changes: 9 additions & 7 deletions oauthapplication/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,31 +107,33 @@ func TestOAuthApplicationClientUpdate(t *testing.T) {
t.Parallel()
id := "app_123"
updatedName := "Updated Application"
callbackURL := "https://updated.callback.url"
callbackURL1 := "https://updated.callback.url"
callbackURL2 := "https://new.callback.url"
public := true

config := &clerk.ClientConfig{}
config.HTTPClient = &http.Client{
Transport: &clerktest.RoundTripper{
T: t,
In: json.RawMessage(fmt.Sprintf(`{"name":"%s","callback_url":"%s", "public":%t}`, updatedName, callbackURL, public)),
Out: json.RawMessage(fmt.Sprintf(`{"id":"%s","name":"%s","callback_url":"%s","public":%t}`, id, updatedName, callbackURL, public)),
In: json.RawMessage(fmt.Sprintf(`{"name":"%s","redirect_uris":["%s","%s"], "public":%t}`, updatedName, callbackURL1, callbackURL2, public)),
Out: json.RawMessage(fmt.Sprintf(`{"id":"%s","name":"%s","redirect_uris":["%s","%s"],"callback_url":"%s","public":%t}`, id, updatedName, callbackURL1, callbackURL2, callbackURL1, public)),
Method: http.MethodPatch,
Path: fmt.Sprintf("/v1/oauth_applications/%s", id),
},
}

client := NewClient(config)
params := &UpdateParams{
Name: clerk.String(updatedName),
CallbackURL: clerk.String(callbackURL),
Public: clerk.Bool(public),
Name: clerk.String(updatedName),
RedirectURIs: []string{callbackURL1, callbackURL2},
Public: clerk.Bool(public),
}
oauthApp, err := client.Update(context.Background(), id, params)
require.NoError(t, err)
require.Equal(t, id, oauthApp.ID)
require.Equal(t, updatedName, oauthApp.Name)
require.Equal(t, callbackURL, oauthApp.CallbackURL)
require.Equal(t, callbackURL1, oauthApp.CallbackURL)
require.Equal(t, []string{callbackURL1, callbackURL2}, oauthApp.RedirectURIs)
}

func TestOrganizationClientUpdate_Error(t *testing.T) {
Expand Down

0 comments on commit f312008

Please sign in to comment.