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

DXCDT:596 Add Metadata Flag to Apps #938

Merged
merged 21 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
4461350
Bump github.com/auth0/go-auth0 from 1.2.0 to 1.3.0 (#908)
dependabot[bot] Nov 13, 2023
2054394
dxcdt-615-goreleaser-upgrade (#909)
Nov 13, 2023
1da3631
DXCDT-582: Convert audience into a drop down in interactive mode in t…
sergiught Nov 11, 2023
7dbf8ea
Merge branch 'main' of https://github.com/auth0/auth0-cli
Nov 13, 2023
1fd7dc2
Merge branch 'main' of https://github.com/auth0/auth0-cli
Nov 16, 2023
60f801c
Merge branch 'main' of https://github.com/auth0/auth0-cli
Nov 22, 2023
b0fd941
Merge remote-tracking branch 'upstream/main'
Nov 29, 2023
be1ef00
Merge branch 'main' of https://github.com/auth0/auth0-cli
Dec 1, 2023
3068c07
Bump goreleaser version
Dec 1, 2023
73e4b3b
Merge branch 'main' of github.com:auth0/auth0-cli into dxcdt-596-add-…
Dec 6, 2023
2383a8e
Add metadata flag to apps create/update
Dec 7, 2023
dd111cd
Improve metadata help
Dec 7, 2023
7f4a84e
Ensure metadata doesn't get wiped on update with no additional metadata
Dec 7, 2023
fe5e95d
Merge branch 'dxcdt-596-add-metadata-flag-to-apps' of github.com:auth…
Dec 7, 2023
40961c4
Show metadata on app show, create, and update rendered views
Dec 7, 2023
a760838
Update metadata docs
Dec 7, 2023
8b14cbf
Merge branch 'main' into dxcdt-596-add-metadata-flag-to-apps
willvedd Dec 7, 2023
0d59e62
Add metadata integration tests
Dec 7, 2023
53a8248
Merge branch 'dxcdt-596-add-metadata-flag-to-apps' of github.com:auth…
Dec 7, 2023
941b955
Remove space sensitivity from integration tests around metadata
Dec 7, 2023
1b597b1
Revert fixture
Dec 7, 2023
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
34 changes: 19 additions & 15 deletions docs/auth0_apps_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,31 @@ auth0 apps create [flags]
auth0 apps create --name myapp --description <description> --type [native|spa|regular|m2m]
auth0 apps create --name myapp --description <description> --type [native|spa|regular|m2m] --reveal-secrets
auth0 apps create -n myapp -d <description> -t [native|spa|regular|m2m] -r --json
auth0 apps create -n myapp -d <description> -t [native|spa|regular|m2m] -r --json --metadata "foo=bar"
auth0 apps create -n myapp -d <description> -t [native|spa|regular|m2m] -r --json --metadata "foo=bar" --metadata "bazz=buzz"
auth0 apps create -n myapp -d <description> -t [native|spa|regular|m2m] -r --json --metadata "foo=bar,bazz=buzz"
```


## Flags

```
-a, --auth-method string Defines the requested authentication method for the token endpoint. Possible values are 'None' (public application without a client secret), 'Post' (application uses HTTP POST parameters) or 'Basic' (application uses HTTP Basic).
-c, --callbacks strings After the user authenticates we will only call back to any of these URLs. You can specify multiple valid URLs by comma-separating them (typically to handle different environments like QA or testing). Make sure to specify the protocol (https://) otherwise the callback may fail in some cases. With the exception of custom URI schemes for native apps, all callbacks should use protocol https://.
-d, --description string Description of the application. Max character count is 140.
-g, --grants strings List of grant types supported for this application. Can include code, implicit, refresh-token, credentials, password, password-realm, mfa-oob, mfa-otp, mfa-recovery-code, and device-code.
--json Output in json format.
-l, --logout-urls strings Comma-separated list of URLs that are valid to redirect to after logout from Auth0. Wildcards are allowed for subdomains.
-n, --name string Name of the application.
-o, --origins strings Comma-separated list of URLs allowed to make requests from JavaScript to Auth0 API (typically used with CORS). By default, all your callback URLs will be allowed. This field allows you to enter other origins if necessary. You can also use wildcards at the subdomain level (e.g., https://*.contoso.com). Query strings and hash information are not taken into account when validating these URLs.
-r, --reveal-secrets Display the application secrets ('signing_keys', 'client_secret') as part of the command output.
-t, --type string Type of application:
- native: mobile, desktop, CLI and smart device apps running natively.
- spa (single page application): a JavaScript front-end app that uses an API.
- regular: Traditional web app using redirects.
- m2m (machine to machine): CLIs, daemons or services running on your backend.
-w, --web-origins strings Comma-separated list of allowed origins for use with Cross-Origin Authentication, Device Flow, and web message response mode.
-a, --auth-method string Defines the requested authentication method for the token endpoint. Possible values are 'None' (public application without a client secret), 'Post' (application uses HTTP POST parameters) or 'Basic' (application uses HTTP Basic).
-c, --callbacks strings After the user authenticates we will only call back to any of these URLs. You can specify multiple valid URLs by comma-separating them (typically to handle different environments like QA or testing). Make sure to specify the protocol (https://) otherwise the callback may fail in some cases. With the exception of custom URI schemes for native apps, all callbacks should use protocol https://.
-d, --description string Description of the application. Max character count is 140.
-g, --grants strings List of grant types supported for this application. Can include code, implicit, refresh-token, credentials, password, password-realm, mfa-oob, mfa-otp, mfa-recovery-code, and device-code.
--json Output in json format.
-l, --logout-urls strings Comma-separated list of URLs that are valid to redirect to after logout from Auth0. Wildcards are allowed for subdomains.
--metadata stringToString Arbitrary keys-value pairs (max 255 characters each), that can be assigned to each application. More about application metadata: https://auth0.com/docs/get-started/applications/configure-application-metadata (default [])
-n, --name string Name of the application.
-o, --origins strings Comma-separated list of URLs allowed to make requests from JavaScript to Auth0 API (typically used with CORS). By default, all your callback URLs will be allowed. This field allows you to enter other origins if necessary. You can also use wildcards at the subdomain level (e.g., https://*.contoso.com). Query strings and hash information are not taken into account when validating these URLs.
-r, --reveal-secrets Display the application secrets ('signing_keys', 'client_secret') as part of the command output.
-t, --type string Type of application:
- native: mobile, desktop, CLI and smart device apps running natively.
- spa (single page application): a JavaScript front-end app that uses an API.
- regular: Traditional web app using redirects.
- m2m (machine to machine): CLIs, daemons or services running on your backend.
-w, --web-origins strings Comma-separated list of allowed origins for use with Cross-Origin Authentication, Device Flow, and web message response mode.
```


Expand Down
34 changes: 19 additions & 15 deletions docs/auth0_apps_update.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,31 @@ auth0 apps update [flags]
auth0 apps update <app-id> --name myapp --description <description> --type [native|spa|regular|m2m]
auth0 apps update <app-id> --name myapp --description <description> --type [native|spa|regular|m2m] --reveal-secrets
auth0 apps update <app-id> -n myapp -d <description> -t [native|spa|regular|m2m] -r --json
auth0 apps update <app-id> -n myapp -d <description> -t [native|spa|regular|m2m] -r --json --metadata "foo=bar"
auth0 apps update <app-id> -n myapp -d <description> -t [native|spa|regular|m2m] -r --json --metadata "foo=bar" --metadata "bazz=buzz"
auth0 apps update <app-id> -n myapp -d <description> -t [native|spa|regular|m2m] -r --json --metadata "foo=bar,bazz=buzz"
```


## Flags

```
-a, --auth-method string Defines the requested authentication method for the token endpoint. Possible values are 'None' (public application without a client secret), 'Post' (application uses HTTP POST parameters) or 'Basic' (application uses HTTP Basic).
-c, --callbacks strings After the user authenticates we will only call back to any of these URLs. You can specify multiple valid URLs by comma-separating them (typically to handle different environments like QA or testing). Make sure to specify the protocol (https://) otherwise the callback may fail in some cases. With the exception of custom URI schemes for native apps, all callbacks should use protocol https://.
-d, --description string Description of the application. Max character count is 140.
-g, --grants strings List of grant types supported for this application. Can include code, implicit, refresh-token, credentials, password, password-realm, mfa-oob, mfa-otp, mfa-recovery-code, and device-code.
--json Output in json format.
-l, --logout-urls strings Comma-separated list of URLs that are valid to redirect to after logout from Auth0. Wildcards are allowed for subdomains.
-n, --name string Name of the application.
-o, --origins strings Comma-separated list of URLs allowed to make requests from JavaScript to Auth0 API (typically used with CORS). By default, all your callback URLs will be allowed. This field allows you to enter other origins if necessary. You can also use wildcards at the subdomain level (e.g., https://*.contoso.com). Query strings and hash information are not taken into account when validating these URLs.
-r, --reveal-secrets Display the application secrets ('signing_keys', 'client_secret') as part of the command output.
-t, --type string Type of application:
- native: mobile, desktop, CLI and smart device apps running natively.
- spa (single page application): a JavaScript front-end app that uses an API.
- regular: Traditional web app using redirects.
- m2m (machine to machine): CLIs, daemons or services running on your backend.
-w, --web-origins strings Comma-separated list of allowed origins for use with Cross-Origin Authentication, Device Flow, and web message response mode.
-a, --auth-method string Defines the requested authentication method for the token endpoint. Possible values are 'None' (public application without a client secret), 'Post' (application uses HTTP POST parameters) or 'Basic' (application uses HTTP Basic).
-c, --callbacks strings After the user authenticates we will only call back to any of these URLs. You can specify multiple valid URLs by comma-separating them (typically to handle different environments like QA or testing). Make sure to specify the protocol (https://) otherwise the callback may fail in some cases. With the exception of custom URI schemes for native apps, all callbacks should use protocol https://.
-d, --description string Description of the application. Max character count is 140.
-g, --grants strings List of grant types supported for this application. Can include code, implicit, refresh-token, credentials, password, password-realm, mfa-oob, mfa-otp, mfa-recovery-code, and device-code.
--json Output in json format.
-l, --logout-urls strings Comma-separated list of URLs that are valid to redirect to after logout from Auth0. Wildcards are allowed for subdomains.
--metadata stringToString Arbitrary keys-value pairs (max 255 characters each), that can be assigned to each application. More about application metadata: https://auth0.com/docs/get-started/applications/configure-application-metadata (default [])
-n, --name string Name of the application.
-o, --origins strings Comma-separated list of URLs allowed to make requests from JavaScript to Auth0 API (typically used with CORS). By default, all your callback URLs will be allowed. This field allows you to enter other origins if necessary. You can also use wildcards at the subdomain level (e.g., https://*.contoso.com). Query strings and hash information are not taken into account when validating these URLs.
-r, --reveal-secrets Display the application secrets ('signing_keys', 'client_secret') as part of the command output.
-t, --type string Type of application:
- native: mobile, desktop, CLI and smart device apps running natively.
- spa (single page application): a JavaScript front-end app that uses an API.
- regular: Traditional web app using redirects.
- m2m (machine to machine): CLIs, daemons or services running on your backend.
-w, --web-origins strings Comma-separated list of allowed origins for use with Cross-Origin Authentication, Device Flow, and web message response mode.
```


Expand Down
36 changes: 34 additions & 2 deletions internal/cli/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ var (
IsRequired: false,
AlwaysPrompt: true,
}
appMetadata = Flag{
Name: "Metadata",
LongForm: "metadata",
Help: "Arbitrary keys-value pairs (max 255 characters each), that can be assigned to each application. More about application metadata: https://auth0.com/docs/get-started/applications/configure-application-metadata",
IsRequired: false,
}
appOrigins = Flag{
Name: "Allowed Origin URLs",
LongForm: "origins",
Expand Down Expand Up @@ -373,6 +379,7 @@ func createAppCmd(cli *cli) *cobra.Command {
AuthMethod string
Grants []string
RevealSecrets bool
Metadata map[string]string
}
var oidcConformant = true
var algorithm = "RS256"
Expand All @@ -389,7 +396,10 @@ func createAppCmd(cli *cli) *cobra.Command {
auth0 apps create --name myapp --description <description>
auth0 apps create --name myapp --description <description> --type [native|spa|regular|m2m]
auth0 apps create --name myapp --description <description> --type [native|spa|regular|m2m] --reveal-secrets
auth0 apps create -n myapp -d <description> -t [native|spa|regular|m2m] -r --json`,
auth0 apps create -n myapp -d <description> -t [native|spa|regular|m2m] -r --json
auth0 apps create -n myapp -d <description> -t [native|spa|regular|m2m] -r --json --metadata "foo=bar"
auth0 apps create -n myapp -d <description> -t [native|spa|regular|m2m] -r --json --metadata "foo=bar" --metadata "bazz=buzz"
auth0 apps create -n myapp -d <description> -t [native|spa|regular|m2m] -r --json --metadata "foo=bar,bazz=buzz"`,
RunE: func(cmd *cobra.Command, args []string) error {
// Prompt for app name
if err := appName.Ask(cmd, &inputs.Name, nil); err != nil {
Expand Down Expand Up @@ -454,6 +464,11 @@ func createAppCmd(cli *cli) *cobra.Command {
}
}

clientMetadata := make(map[string]interface{}, len(inputs.Metadata))
for k, v := range inputs.Metadata {
clientMetadata[k] = v
}

// Load values into a fresh app instance
a := &management.Client{
Name: &inputs.Name,
Expand All @@ -465,6 +480,7 @@ func createAppCmd(cli *cli) *cobra.Command {
AllowedLogoutURLs: stringSliceToPtr(inputs.AllowedLogoutURLs),
OIDCConformant: &oidcConformant,
JWTConfiguration: &management.ClientJWTConfiguration{Algorithm: &algorithm},
ClientMetadata: &clientMetadata,
}

// Set token endpoint auth method
Expand Down Expand Up @@ -505,6 +521,7 @@ func createAppCmd(cli *cli) *cobra.Command {
appDescription.RegisterString(cmd, &inputs.Description, "")
appCallbacks.RegisterStringSlice(cmd, &inputs.Callbacks, nil)
appOrigins.RegisterStringSlice(cmd, &inputs.AllowedOrigins, nil)
appMetadata.RegisterStringMap(cmd, &inputs.Metadata, nil)
appWebOrigins.RegisterStringSlice(cmd, &inputs.AllowedWebOrigins, nil)
appLogoutURLs.RegisterStringSlice(cmd, &inputs.AllowedLogoutURLs, nil)
appAuthMethod.RegisterString(cmd, &inputs.AuthMethod, "")
Expand All @@ -527,6 +544,7 @@ func updateAppCmd(cli *cli) *cobra.Command {
AuthMethod string
Grants []string
RevealSecrets bool
Metadata map[string]string
}

cmd := &cobra.Command{
Expand All @@ -542,7 +560,10 @@ func updateAppCmd(cli *cli) *cobra.Command {
auth0 apps update <app-id> --name myapp --description <description>
auth0 apps update <app-id> --name myapp --description <description> --type [native|spa|regular|m2m]
auth0 apps update <app-id> --name myapp --description <description> --type [native|spa|regular|m2m] --reveal-secrets
auth0 apps update <app-id> -n myapp -d <description> -t [native|spa|regular|m2m] -r --json`,
auth0 apps update <app-id> -n myapp -d <description> -t [native|spa|regular|m2m] -r --json
auth0 apps update <app-id> -n myapp -d <description> -t [native|spa|regular|m2m] -r --json --metadata "foo=bar"
auth0 apps update <app-id> -n myapp -d <description> -t [native|spa|regular|m2m] -r --json --metadata "foo=bar" --metadata "bazz=buzz"
auth0 apps update <app-id> -n myapp -d <description> -t [native|spa|regular|m2m] -r --json --metadata "foo=bar,bazz=buzz"`,
RunE: func(cmd *cobra.Command, args []string) error {
var current *management.Client

Expand Down Expand Up @@ -695,6 +716,16 @@ func updateAppCmd(cli *cli) *cobra.Command {
a.GrantTypes = apiGrantsFor(inputs.Grants)
}

if len(inputs.Metadata) == 0 {
a.ClientMetadata = current.ClientMetadata
} else {
clientMetadata := make(map[string]interface{}, len(inputs.Metadata))
for k, v := range inputs.Metadata {
clientMetadata[k] = v
}
a.ClientMetadata = &clientMetadata
}

// Update app
if err := ansi.Waiting(func() error {
return cli.api.Client.Update(cmd.Context(), inputs.ID, a)
Expand All @@ -714,6 +745,7 @@ func updateAppCmd(cli *cli) *cobra.Command {
appType.RegisterStringU(cmd, &inputs.Type, "")
appDescription.RegisterStringU(cmd, &inputs.Description, "")
appCallbacks.RegisterStringSliceU(cmd, &inputs.Callbacks, nil)
appMetadata.RegisterStringMap(cmd, &inputs.Metadata, map[string]string{})
appOrigins.RegisterStringSliceU(cmd, &inputs.AllowedOrigins, nil)
appWebOrigins.RegisterStringSliceU(cmd, &inputs.AllowedWebOrigins, nil)
appLogoutURLs.RegisterStringSliceU(cmd, &inputs.AllowedLogoutURLs, nil)
Expand Down
15 changes: 15 additions & 0 deletions internal/display/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type applicationView struct {
AllowedLogoutURLs []string
AuthMethod string
Grants []string
Metadata []string
revealSecret bool

raw interface{}
Expand Down Expand Up @@ -68,6 +69,7 @@ func (v *applicationView) KeyValues() [][]string {
allowedWebOrigins := strings.Join(v.AllowedWebOrigins, ", ")
allowedLogoutURLs := strings.Join(v.AllowedLogoutURLs, ", ")
grants := strings.Join(v.Grants, ", ")
metadata := strings.Join(v.Metadata, ", ")

if v.revealSecret {
return [][]string{
Expand All @@ -82,6 +84,7 @@ func (v *applicationView) KeyValues() [][]string {
{"ALLOWED WEB ORIGINS", allowedWebOrigins},
{"TOKEN ENDPOINT AUTH", v.AuthMethod},
{"GRANTS", grants},
{"METADATA", metadata},
}
}

Expand All @@ -96,6 +99,7 @@ func (v *applicationView) KeyValues() [][]string {
{"ALLOWED WEB ORIGINS", allowedWebOrigins},
{"TOKEN ENDPOINT AUTH", v.AuthMethod},
{"GRANTS", grants},
{"METADATA", metadata},
}
}

Expand Down Expand Up @@ -176,6 +180,7 @@ func makeApplicationView(client *management.Client, revealSecrets bool) *applica
AllowedLogoutURLs: client.GetAllowedLogoutURLs(),
AuthMethod: client.GetTokenEndpointAuthMethod(),
Grants: client.GetGrantTypes(),
Metadata: mapPointerToArray(client.ClientMetadata),
raw: client,
}
}
Expand All @@ -197,6 +202,16 @@ func FriendlyAppType(appType string) string {
}
}

func mapPointerToArray(m *map[string]interface{}) []string {
var result []string
if m != nil {
for k, v := range *m {
result = append(result, fmt.Sprintf("%s=%v", k, v))
}
}
return result
}

func quickstartsURIFor(appType string) string {
switch {
case appType == "native":
Expand Down
Loading
Loading