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