Skip to content
Closed
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 {
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
}
45 changes: 45 additions & 0 deletions demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash

run() {
echo -e "\e[33m\$ $*\e[0m"
read -r
"$@"
echo ""
}

clear
echo "imscli Demo"
echo ""
read -r

# 1. DCR
run ./imscli dcr register \
--url https://ims-na1-stg1.adobelogin.com \
--clientName "My App" \
--redirectURIs "http://localhost:8888" \
--scopes "openid AdobeID"

read -r -p "client_id: " CLIENT_ID
read -r -p "client_secret: " CLIENT_SECRET

# 2. Authz
echo -e "\e[33m\$ ./imscli authz user --url https://ims-na1-stg1.adobelogin.com --clientID $CLIENT_ID --clientSecret $CLIENT_SECRET --scopes \"openid AdobeID\" --organization \"96D656605F9846070A494236@AdobeOrg\"\e[0m"
read -r
ACCESS_TOKEN=$(./imscli authz user \
--url https://ims-na1-stg1.adobelogin.com \
--clientID "$CLIENT_ID" \
--clientSecret "$CLIENT_SECRET" \
--scopes "openid AdobeID" \
--organization "96D656605F9846070A494236@AdobeOrg")
echo "$ACCESS_TOKEN"
echo ""

# 3. OBO
run ./imscli obo \
--url https://ims-na1-stg1.adobelogin.com \
--clientID "imscli" \
--clientSecret "s8e-QZ9CnNQq2W6J_suZdqNd__BaaXokfZVq" \
--accessToken "$ACCESS_TOKEN" \
--scopes "openid AdobeID"

echo -e "\e[32mDone!\e[0m"
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
61 changes: 61 additions & 0 deletions ims/dcr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// 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"
)

const (
dcrRegisterPath = "/ims/register"

Check failure on line 22 in ims/dcr.go

View workflow job for this annotation

GitHub Actions / Lint

const dcrRegisterPath is unused (unused)
maxDCRResponseBodySize = 1 << 20 // 1 MiB

Check failure on line 23 in ims/dcr.go

View workflow job for this annotation

GitHub Actions / Lint

const maxDCRResponseBodySize is unused (unused)
)

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