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 { // Check if expiry is what we expect. var tok returnToken err = json.Unmarshal(b, &tok) if err != nil { log.Fatalf("error while unmarshalling token from file %v", err) } if tok.ExpiryTime.After(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) } scopes := []string{oidc.ScopeOpenID} scopes = append(scopes, viper.GetStringSlice("auth.scopes")...) fmt.Printf("%s", scopes) 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: scopes, } tokenChan := make(chan *returnToken) w := &web{ verifier: provider.Verifier(&oidc.Config{ClientID: viper.GetString("auth.client_id")}), 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.