Skip to content

Commit

Permalink
Merge branch 'main' into CLI-36
Browse files Browse the repository at this point in the history
  • Loading branch information
Widcket committed Feb 26, 2021
2 parents 9c6ee16 + d0d5dd2 commit 838cfc9
Show file tree
Hide file tree
Showing 10 changed files with 474 additions and 335 deletions.
20 changes: 4 additions & 16 deletions internal/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,6 @@ import (
"time"
)

// 1st request
// curl --request POST \
// --url 'https://auth0.auth0.com/oauth/device/code' \
// --header 'content-type: application/x-www-form-urlencoded' \
// --data 'client_id=2iZo3Uczt5LFHacKdM0zzgUO2eG2uDjT' \
// --data 'scope=openid read:roles' \
// --data audience=https://\*.auth0.com/api/v2/

// polling request
// curl --request POST \
// --url 'https://auth0.auth0.com/oauth/token' \
// --header 'content-type: application/x-www-form-urlencoded' \
// --data grant_type=urn:ietf:params:oauth:grant-type:device_code \
// --data device_code=9GtgUcsGKzXkU-i70RN74baY \
// --data 'client_id=2iZo3Uczt5LFHacKdM0zzgUO2eG2uDjT'

const (
clientID = "2iZo3Uczt5LFHacKdM0zzgUO2eG2uDjT"
deviceCodeEndpoint = "https://auth0.auth0.com/oauth/device/code"
Expand Down Expand Up @@ -65,6 +49,9 @@ func (s *State) IntervalDuration() time.Duration {
return time.Duration(s.Interval) * time.Second
}

// Start kicks-off the device authentication flow
// by requesting a device code from Auth0,
// The returned state contains the URI for the next step of the flow.
func (a *Authenticator) Start(ctx context.Context) (State, error) {
s, err := a.getDeviceCode(ctx)
if err != nil {
Expand All @@ -73,6 +60,7 @@ func (a *Authenticator) Start(ctx context.Context) (State, error) {
return s, nil
}

// Wait waits until the user is logged in on the browser.
func (a *Authenticator) Wait(ctx context.Context, state State) (Result, error) {
t := time.NewTicker(state.IntervalDuration())
for {
Expand Down
12 changes: 3 additions & 9 deletions internal/cli/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ auth0 apis create --name myapi --identifier http://my-api
if shouldPrompt(cmd, apiName) {
input := prompt.TextInput(
apiName, "Name:",
"Name of the API. You can change the API name later in the API settings.",
"Name of the API. You can change the name later in the API settings.",
true)

if err := prompt.AskOne(input, &flags); err != nil {
Expand Down Expand Up @@ -265,7 +265,7 @@ auth0 apis update --id id --name myapi
cmd.Flags().StringVarP(&flags.ID, apiID, "i", "", "ID of the API.")
cmd.Flags().StringVarP(&flags.Name, apiName, "n", "", "Name of the API.")
cmd.Flags().StringVarP(&flags.Scopes, apiScopes, "s", "", "Space-separated list of scopes.")
mustRequireFlags(cmd, apiID, apiName)
mustRequireFlags(cmd, apiID)

return cmd
}
Expand Down Expand Up @@ -300,15 +300,9 @@ auth0 apis delete --id id
}
}

err := ansi.Spinner("Deleting API", func() error {
return ansi.Spinner("Deleting API", func() error {
return cli.api.ResourceServer.Delete(flags.ID)
})

if err != nil {
return err
}

return nil
},
}

Expand Down
Loading

0 comments on commit 838cfc9

Please sign in to comment.