Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 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
5 changes: 3 additions & 2 deletions cmd/dcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ func registerCmd(imsConfig *ims.Config) *cobra.Command {
Use: "register",
Short: "Register a client.",
Long: `Register a new OAuth client using Dynamic Client Registration.`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, asrgs []string) error {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

args is good

cmd.SilenceUsage = true

resp, err := imsConfig.Register()
resp, err := imsConfig.DCRRegister()
if err != nil {
return fmt.Errorf("error during client registration: %w", err)
}
Expand All @@ -50,6 +50,7 @@ func registerCmd(imsConfig *ims.Config) *cobra.Command {

cmd.Flags().StringVarP(&imsConfig.ClientName, "clientName", "n", "", "Client application name.")
cmd.Flags().StringSliceVarP(&imsConfig.RedirectURIs, "redirectURIs", "r", []string{}, "Redirect URIs (comma-separated or multiple flags).")
cmd.Flags().StringSliceVarP(&imsConfig.Scopes, "scopes", "s", []string{}, "Requested scopes (comma-separated or multiple flags).")

return cmd
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ go 1.23.0
toolchain go1.26.2

require (
github.com/adobe/ims-go v0.21.0
github.com/adobe/ims-go v0.22.0
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
github.com/spf13/cobra v1.10.2
github.com/spf13/viper v1.21.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/adobe/ims-go v0.21.0 h1:Y0uBT0Fho54ZXhVY0wvT6FUGrM3OEg4J4aJb0fUQdKQ=
github.com/adobe/ims-go v0.21.0/go.mod h1:zGpx0ylsumBjkgd8fYgzJ8+Ci/zFABiBTAxbCscsyR8=
github.com/adobe/ims-go v0.22.0 h1:fN9sUoET8ytkv58aLEDCaUUTyXwsIpRjoSNy87EkbwU=
github.com/adobe/ims-go v0.22.0/go.mod h1:zGpx0ylsumBjkgd8fYgzJ8+Ci/zFABiBTAxbCscsyR8=
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
4 changes: 2 additions & 2 deletions ims/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func TestValidateAuthorizeClientCredentialsConfig(t *testing.T) {
}
}

func TestValidateRegisterConfig(t *testing.T) {
func TestValidateDCRConfig(t *testing.T) {
tests := []struct {
name string
config Config
Expand All @@ -308,7 +308,7 @@ func TestValidateRegisterConfig(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.config.validateRegisterConfig()
err := tt.config.validateDCRConfig()
assertError(t, err, tt.wantErr)
})
}
Expand Down
56 changes: 56 additions & 0 deletions ims/dcr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2026 Adobe. All rights reserved.
// This file is licensed to you under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may obtain a copy
// of the License at http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
// OF ANY KIND, either express or implied. See the License for the specific language
// governing permissions and limitations under the License.

// Dynamic Client Registration (DCR): POST JSON to IMS /ims/register.

package ims

import (
"fmt"

"github.com/adobe/ims-go/ims"
)

func (i Config) validateDCRConfig() error {
switch {
case i.URL == "":
return fmt.Errorf("missing IMS base URL parameter")
case !validateURL(i.URL):
return fmt.Errorf("invalid IMS base URL parameter")
case i.ClientName == "":
return fmt.Errorf("missing client name parameter")
case len(i.RedirectURIs) == 0:
return fmt.Errorf("missing redirect URIs parameter")
default:
return nil
}
}

func (i Config) DCRRegister() (string, error) {
if err := i.validateDCRConfig(); err != nil {
return "", fmt.Errorf("invalid parameters for client registration: %w", err)
}

c, err := i.newIMSClient()
if err != nil {
return "", fmt.Errorf("error creating the IMS client: %w", err)
}

resp, err := c.DCR(&ims.DCRRequest{
ClientName: i.ClientName,
RedirectURIs: i.RedirectURIs,
Scopes: i.Scopes,
})
if err != nil {
return "", fmt.Errorf("error during client registration: %w", err)
}

return string(resp.Body), nil
}
80 changes: 0 additions & 80 deletions ims/register.go

This file was deleted.

Loading