Skip to content

Commit

Permalink
enhance: ringcentral/examples/get_token: add `ringcentral.NewTokenC…
Browse files Browse the repository at this point in the history
…li()` support
  • Loading branch information
grokify committed Jul 30, 2021
1 parent c1357da commit b188970
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions ringcentral/examples/get_token/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import (
"fmt"

"github.com/grokify/oauth2more/credentials"
"github.com/grokify/oauth2more/ringcentral"
"github.com/grokify/simplego/fmt/fmtutil"
"github.com/jessevdk/go-flags"
"github.com/rs/zerolog/log"
"golang.org/x/oauth2"
)

type Options struct {
CredsPath string `short:"c" long:"credspath" description:"Environment File Path"`
Account string `short:"a" long:"account" description:"Environment Variable Name"`
Token string `short:"t" long:"token" description:"Token"`
CredsPath string `short:"c" long:"credspath" description:"Environment File Path"`
AccountKey string `short:"a" long:"account" description:"Environment Variable Name"`
Token string `short:"t" long:"token" description:"Token"`
CLI []bool `long:"cli" description:"CLI"`
}

func main() {
Expand All @@ -30,18 +33,28 @@ func main() {
Msg("cannot read credentials file")
}

credentials, err := cset.Get(opts.Account)
credentials, err := cset.Get(opts.AccountKey)
if err != nil {
log.Fatal().Err(err).
Str("credentials_account", opts.Account).
Str("credentials_account", opts.AccountKey).
Msg("cannot find credentials account")
panic("fail1")
}

token, err := credentials.NewToken()
var token *oauth2.Token

if len(opts.CLI) > 0 {
token, err = ringcentral.NewTokenCli(credentials, "mystate")
} else {
token, err = credentials.NewToken()
}
if err != nil {
log.Fatal().Err(err).Msg("cannot get new token")
panic("fail2")
log.Fatal().
Err(err).
Str("filepath", opts.CredsPath).
Str("account", opts.AccountKey).
Msg("failed to get new token")
panic("failed")
}

token.Expiry = token.Expiry.UTC()
Expand Down

0 comments on commit b188970

Please sign in to comment.