Skip to content

Commit

Permalink
CLI-34: Attempt to validate access token when checking if the user is
Browse files Browse the repository at this point in the history
logged in.
  • Loading branch information
rene00 committed Feb 24, 2021
1 parent 5369bc0 commit 5e86185
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion internal/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/auth0/auth0-cli/internal/ansi"
"github.com/auth0/auth0-cli/internal/auth0"
"github.com/auth0/auth0-cli/internal/display"
"github.com/lestrrat-go/jwx/jwt"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"gopkg.in/auth0.v5/management"
Expand Down Expand Up @@ -79,7 +80,23 @@ func (c *cli) isLoggedIn() bool {
// No need to check errors for initializing context.
_ = c.init()

return c.tenant != ""
if c.tenant == "" {
return false
}

// Parse the access token for the tenant.
t, err := jwt.ParseString(c.config.Tenants[c.tenant].AccessToken)
if err != nil {
return false
}

// Check if token is valid.
if err = jwt.Validate(t); err != nil {
return false
}

return true

}

// setup will try to initialize the config context, as well as figure out if
Expand Down

0 comments on commit 5e86185

Please sign in to comment.