github.com/mhlo/force@v0.22.28-0.20150915022417-6d05ecfb0b47/oauth.go (about) 1 package main 2 3 import ( 4 "fmt" 5 ) 6 7 var cmdOauth = &Command{ 8 Run: runOauth, 9 Usage: "oauth <command> [<args>]", 10 Short: "Manage ConnectedApp credentials", 11 Long: ` 12 Manage ConnectedApp credentials 13 14 Usage: 15 16 force oauth create <name> <callback> 17 18 Examples: 19 20 force oauth create MyApp https://myapp.herokuapp.com/auth/callback 21 `, 22 } 23 24 func runOauth(cmd *Command, args []string) { 25 if len(args) == 0 { 26 cmd.printUsage() 27 } else { 28 switch args[0] { 29 case "create", "add": 30 runOauthCreate(cmd, args[1:]) 31 default: 32 ErrorAndExit("no such command: %s", args[0]) 33 } 34 } 35 } 36 37 func runOauthCreate(cmd *Command, args []string) { 38 if len(args) != 2 { 39 ErrorAndExit("must specify name and callback") 40 } 41 force, _ := ActiveForce() 42 err := force.Metadata.CreateConnectedApp(args[0], args[1]) 43 if err != nil { 44 ErrorAndExit(err.Error()) 45 } 46 apps, err := force.Metadata.ListConnectedApps() 47 if err != nil { 48 ErrorAndExit(err.Error()) 49 } 50 runFetch(cmd, []string{"ConnectedApp", args[0]}) 51 for _, app := range apps { 52 if app.Name == args[0] { 53 //url := fmt.Sprintf("%s/%s", force.Credentials.InstanceUrl, app.Id) 54 //Open(url) 55 } 56 } 57 fmt.Println("OAuth credentials created") 58 }