Skip to content

Commit

Permalink
Merge branch 'v1' into DXCDT-298-interactive-login-prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiught authored Dec 9, 2022
2 parents d2ea263 + 3e367a5 commit 51d95ed
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 96 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Go

on: [push, pull_request]

env:
GO_VERSION: 1.19.4

concurrency:
group: one-at-time
cancel-in-progress: false
Expand All @@ -18,7 +21,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19.3
go-version: ${{env.GO_VERSION}}

- name: Check out the code
uses: actions/checkout@v3
Expand All @@ -45,7 +48,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19.3
go-version: ${{env.GO_VERSION}}

- name: Check out the code
uses: actions/checkout@v3
Expand All @@ -58,8 +61,6 @@ jobs:
AUTH0_CLI_CLIENT_DOMAIN: ${{ secrets.AUTH0_CLI_CLIENT_DOMAIN }}
AUTH0_CLI_CLIENT_ID: ${{ secrets.AUTH0_CLI_CLIENT_ID }}
AUTH0_CLI_CLIENT_SECRET: ${{ secrets.AUTH0_CLI_CLIENT_SECRET }}
AUTH0_CLI_REUSE_CONFIG: ${{ secrets.AUTH0_CLI_REUSE_CONFIG }}
AUTH0_CLI_OVERWRITE: ${{ secrets.AUTH0_CLI_OVERWRITE }}

build:
name: Build
Expand All @@ -72,7 +73,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19.3
go-version: ${{env.GO_VERSION}}

- name: Check out the code
uses: actions/checkout@v3
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
pull_request:
push:

env:
GO_VERSION: 1.19.4

jobs:
goreleaser:
runs-on: ubuntu-latest
Expand All @@ -20,7 +23,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19.3
go-version: ${{env.GO_VERSION}}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
Expand Down
11 changes: 1 addition & 10 deletions cmd/build_doc/main.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
package main

import (
"github.com/joeshaw/envdecode"

"github.com/auth0/auth0-cli/internal/cli"
)

func main() {
var cfg struct {
Path string `env:"AUTH0_CLI_DOCS_PATH,default=./docs/"`
}
if err := envdecode.StrictDecode(&cfg); err != nil {
panic(err)
}

err := cli.BuildDoc(cfg.Path)
err := cli.BuildDoc()
if err != nil {
panic(err)
}
Expand Down
8 changes: 4 additions & 4 deletions docs/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,20 @@ GEM
jekyll-feed (~> 0.9)
jekyll-seo-tag (~> 2.1)
minitest (5.16.3)
nokogiri (1.13.9)
nokogiri (1.13.10)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
nokogiri (1.13.9-x86_64-darwin)
nokogiri (1.13.10-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.13.9-x86_64-linux)
nokogiri (1.13.10-x86_64-linux)
racc (~> 1.4)
octokit (4.25.1)
faraday (>= 1, < 3)
sawyer (~> 0.9)
pathutil (0.16.2)
forwardable-extended (~> 2.6)
public_suffix (4.0.7)
racc (1.6.0)
racc (1.6.1)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
Expand Down
14 changes: 6 additions & 8 deletions docs/auth0_login.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Authenticate the Auth0 CLI

### Synopsis

Authenticates the Auth0 CLI either as a user using personal credentials or as a machine using client credentials (client ID/secret).
Authenticates the Auth0 CLI either as a user using personal credentials or as a machine using client credentials.

```
auth0 login [flags]
Expand All @@ -16,18 +16,16 @@ auth0 login [flags]
### Examples

```
auth0 login
auth0 login --domain <tenant-domain> --client-id <client-id> --client-secret <client-secret>
auth0 login
auth0 login --domain <tenant-domain> --client-id <client-id> --client-secret <client-secret>
```

### Options

```
-i, --client-id string Client ID of the application.
-s, --client-secret string Client Secret of the application.
--domain string Specifies tenant domain when authenticating via client credentials (client ID, client secret)
--client-id string Client ID of the application when authenticating via client credentials.
--client-secret string Client secret of the application when authenticating via client credentials.
--domain string Tenant domain of the application when authenticating via client credentials.
-h, --help help for login
```

Expand Down
25 changes: 0 additions & 25 deletions docs/ci.md

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/briandowns/spinner v1.19.0
github.com/charmbracelet/glamour v0.6.0
github.com/fsnotify/fsnotify v1.6.0
github.com/getsentry/sentry-go v0.15.0
github.com/getsentry/sentry-go v0.16.0
github.com/golang/mock v1.6.0
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYF
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/getsentry/sentry-go v0.15.0 h1:CP9bmA7pralrVUedYZsmIHWpq/pBtXTSew7xvVpfLaA=
github.com/getsentry/sentry-go v0.15.0/go.mod h1:RZPJKSw+adu8PBNygiri/A98FqVr2HtRckJk9XVxJ9I=
github.com/getsentry/sentry-go v0.16.0 h1:owk+S+5XcgJLlGR/3+3s6N4d+uKwqYvh/eS0AIMjPWo=
github.com/getsentry/sentry-go v0.16.0/go.mod h1:ZXCloQLj0pG7mja5NK6NPf2V4A88YJ4pNlc2mOHwh6Y=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
Expand Down
4 changes: 2 additions & 2 deletions internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ type ClientCredentials struct {
}

// GetAccessTokenFromClientCreds generates an access token from client credentials
func GetAccessTokenFromClientCreds(args ClientCredentials) (Result, error) {
func GetAccessTokenFromClientCreds(ctx context.Context, args ClientCredentials) (Result, error) {
u, err := url.Parse("https://" + args.Domain)
if err != nil {
return Result{}, err
Expand All @@ -305,7 +305,7 @@ func GetAccessTokenFromClientCreds(args ClientCredentials) (Result, error) {
},
}

resp, err := credsConfig.Token(context.Background())
resp, err := credsConfig.Token(ctx)
if err != nil {
return Result{}, err
}
Expand Down
6 changes: 4 additions & 2 deletions internal/cli/build_doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/spf13/cobra/doc"
)

func BuildDoc(path string) error {
func BuildDoc() error {
cli := &cli{}

rootCmd := &cobra.Command{
Expand All @@ -20,8 +20,10 @@ func BuildDoc(path string) error {
addPersistentFlags(rootCmd, cli)
addSubcommands(rootCmd, cli)

docsPath := "./docs/"

err := doc.GenMarkdownTreeCustom(rootCmd,
path,
docsPath,
func(fileName string) string {
// prepend to the generated markdown
if strings.HasSuffix(fileName, "auth0.md") {
Expand Down
27 changes: 18 additions & 9 deletions internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/spf13/pflag"

"github.com/auth0/auth0-cli/internal/analytics"
"github.com/auth0/auth0-cli/internal/ansi"
"github.com/auth0/auth0-cli/internal/auth"
"github.com/auth0/auth0-cli/internal/auth0"
"github.com/auth0/auth0-cli/internal/buildinfo"
Expand Down Expand Up @@ -109,11 +110,14 @@ func (t *Tenant) hasExpiredToken() bool {

func (t *Tenant) regenerateAccessToken(ctx context.Context, c *cli) error {
if t.authenticatedWithClientCredentials() {
token, err := auth.GetAccessTokenFromClientCreds(auth.ClientCredentials{
ClientID: t.ClientID,
ClientSecret: t.ClientSecret,
Domain: t.Domain,
})
token, err := auth.GetAccessTokenFromClientCreds(
ctx,
auth.ClientCredentials{
ClientID: t.ClientID,
ClientSecret: t.ClientSecret,
Domain: t.Domain,
},
)
if err != nil {
return err
}
Expand Down Expand Up @@ -208,7 +212,7 @@ func (c *cli) prepareTenant(ctx context.Context) (Tenant, error) {
}

if scopesChanged(t) && t.authenticatedWithDeviceCodeFlow() {
c.renderer.Warnf("Required scopes have changed. Please log in to re-authorize the CLI.")
c.renderer.Warnf("Required scopes have changed. Please log in to re-authorize the CLI.\n")
return RunLoginAsUser(ctx, c)
}

Expand All @@ -218,12 +222,17 @@ func (c *cli) prepareTenant(ctx context.Context) (Tenant, error) {

if err := t.regenerateAccessToken(ctx, c); err != nil {
if t.authenticatedWithClientCredentials() {
return t, fmt.Errorf("Failed to renew access token. This may occur if the designated application has been deleted or client secret has been rotated. Please re-authenticate by running `auth0 login --as-machine`")
return t, fmt.Errorf(
"failed to fetch access token using client credentials.\n\n"+
"This may occur if the designated application has been deleted or the client secret has been rotated.\n\n"+
"Please re-authenticate by running: %s",
ansi.Bold("auth0 login --domain <tenant-domain --client-id <client-id> --client-secret <client-secret>"),
)
}

c.renderer.Warnf("Failed to renew access token. Please log in to re-authorize the CLI.")
return RunLoginAsUser(ctx, c)
c.renderer.Warnf("Failed to renew access token. Please log in to re-authorize the CLI.\n")

return RunLoginAsUser(ctx, c)
}

if err := c.addTenant(t); err != nil {
Expand Down
Loading

0 comments on commit 51d95ed

Please sign in to comment.