Refactored and added client credentials flow

This commit is contained in:
David Allen 2024-02-29 20:14:53 -07:00
parent f912890a2d
commit f490eb4fc4
No known key found for this signature in database
GPG key ID: 1D2A29322FBB6FCB
9 changed files with 113 additions and 41 deletions

View file

@ -1,7 +1,7 @@
package cmd
import (
opaal "davidallendj/opaal/internal"
"davidallendj/opaal/internal/flows"
"fmt"
"os"
@ -13,7 +13,7 @@ var loginCmd = &cobra.Command{
Short: "Start the login flow",
Run: func(cmd *cobra.Command, args []string) {
for {
err := opaal.Login(&config)
err := flows.Login(&config)
if err != nil {
fmt.Printf("%v\n", err)
os.Exit(1)
@ -37,5 +37,6 @@ func init() {
loginCmd.Flags().BoolVar(&config.DecodeIdToken, "decode-id-token", config.DecodeIdToken, "decode and print ID token from identity provider")
loginCmd.Flags().BoolVar(&config.DecodeAccessToken, "decore-access-token", config.DecodeAccessToken, "decode and print access token from authorization server")
loginCmd.Flags().BoolVar(&config.RunOnce, "once", config.RunOnce, "set whether to run login once and exit")
loginCmd.Flags().StringVar(&config.GrantType, "grant-type", config.GrantType, "set the grant-type/authorization flow")
rootCmd.AddCommand(loginCmd)
}

View file

@ -21,6 +21,18 @@ var rootCmd = &cobra.Command{
},
}
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "failed to start CLI: %s", err)
os.Exit(1)
}
}
func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&configPath, "config", "", "set the config path")
}
func initConfig() {
// load config if found or create a new one
if configPath != "" {
@ -35,15 +47,3 @@ func initConfig() {
}
}
}
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "failed to start CLI: %s", err)
os.Exit(1)
}
}
func init() {
cobra.OnInitialize(initConfig)
rootCmd.PersistentFlags().StringVar(&configPath, "config", "", "set the config path")
}