Skip to content

Commit

Permalink
Add default Token Endpoint Auth Method on apps create [CLI-115] (#217)
Browse files Browse the repository at this point in the history
* Add default Token Endpoint Auth method

* Update internal/cli/apps.go

Co-authored-by: Cyril David <cyx@users.noreply.github.com>

Co-authored-by: Cyril David <cyx@users.noreply.github.com>
  • Loading branch information
Widcket and cyx authored Apr 2, 2021
1 parent 7c8657b commit 536c380
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions internal/cli/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,16 +381,22 @@ auth0 apps create -n myapp -t [native|spa|regular|m2m] -- description <descripti

// Load values into a fresh app instance
a := &management.Client{
Name: &inputs.Name,
Description: &inputs.Description,
AppType: auth0.String(apiTypeFor(inputs.Type)),
Callbacks: stringToInterfaceSlice(inputs.Callbacks),
AllowedOrigins: stringToInterfaceSlice(inputs.AllowedOrigins),
WebOrigins: stringToInterfaceSlice(inputs.AllowedWebOrigins),
AllowedLogoutURLs: stringToInterfaceSlice(inputs.AllowedLogoutURLs),
TokenEndpointAuthMethod: apiAuthMethodFor(inputs.AuthMethod),
OIDCConformant: &oidcConformant,
JWTConfiguration: &management.ClientJWTConfiguration{Algorithm: &algorithm},
Name: &inputs.Name,
Description: &inputs.Description,
AppType: auth0.String(apiTypeFor(inputs.Type)),
Callbacks: stringToInterfaceSlice(inputs.Callbacks),
AllowedOrigins: stringToInterfaceSlice(inputs.AllowedOrigins),
WebOrigins: stringToInterfaceSlice(inputs.AllowedWebOrigins),
AllowedLogoutURLs: stringToInterfaceSlice(inputs.AllowedLogoutURLs),
OIDCConformant: &oidcConformant,
JWTConfiguration: &management.ClientJWTConfiguration{Algorithm: &algorithm},
}

// Set token endpoint auth method
if len(inputs.AuthMethod) == 0 {
a.TokenEndpointAuthMethod = apiDefaultAuthMethodFor(inputs.Type)
} else {
a.TokenEndpointAuthMethod = apiAuthMethodFor(inputs.AuthMethod)
}

// Set grants
Expand Down Expand Up @@ -666,6 +672,15 @@ func apiAuthMethodFor(v string) *string {
}
}

func apiDefaultAuthMethodFor(t string) *string {
switch apiTypeFor(strings.ToLower(t)) {
case appTypeNative, appTypeSPA:
return auth0.String("none")
default:
return nil
}
}

func apiGrantsFor(s []string) []interface{} {
res := make([]interface{}, len(s))

Expand Down

0 comments on commit 536c380

Please sign in to comment.