Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var RootCmd = &cobra.Command{ Use: "dexy", Short: "", Long: `Dexy is a simple application used to grab an oauth2 token from a provider`, Run: func(cmd *cobra.Command, args []string) { b, err := ioutil.ReadFile(viper.GetString("token_file")) if err == nil { tok := &oauth2.Token{} err = json.Unmarshal(b, tok) if err != nil { log.Fatalf("error while unmarshalling token from file %v", err) } if !tok.Expiry.Before(time.Now()) { fmt.Println(string(b)) return } } provider, err := oidc.NewProvider(context.Background(), viper.GetString("auth.dex_host")) if err != nil { log.Fatalf("error while creating new oidc provider %v", err) } oauth2Config := oauth2.Config{ ClientID: viper.GetString("auth.client_id"), ClientSecret: viper.GetString("auth.client_secret"), RedirectURL: viper.GetString("auth.callback_url"), Endpoint: provider.Endpoint(), Scopes: []string{oidc.ScopeOpenID, "groups", "email"}, } tokenChan := make(chan *oauth2.Token) w := &web{ cfg: oauth2Config, tokenChan: tokenChan, } err = browser.OpenURL(oauth2Config.AuthCodeURL("")) if err != nil { log.Fatalf("error while opening new web browser %v", err) } go w.Serve() tok := <-tokenChan b, err = json.Marshal(tok) if err != nil { log.Fatalf("error while marshalling token from provider %v", err) } err = ioutil.WriteFile(viper.GetString("token_file"), b, 0755) if err != nil { log.Fatalf("error while attempting to write token to file %v", err) } fmt.Println(string(b)) }, }
RootCmd represents the base command when called without any subcommands
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.