-
Notifications
You must be signed in to change notification settings - Fork 5
/
oauth_commands.go
96 lines (87 loc) · 2.81 KB
/
oauth_commands.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"os"
"github.com/clusterit/orca/auth/oauth"
"github.com/spf13/cobra"
)
var (
loginscope string
scopes string
authUrl string
accessTokenUrl string
userinfoUrl string
pathid string
pathname string
pathpicture string
pathcover string
)
var oauthCmd = &cobra.Command{
Use: "oauth",
Short: "show, register and unregister oauth providers",
Long: "show, register and unregister oauth providers",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}
var oauthList = &cobra.Command{
Use: "list",
Short: "list all registered oauth providers",
Long: "list all registered oauth providers",
Run: func(cmd *cobra.Command, args []string) {
c := newCli()
res, err := c.listOauthProviders()
exitWhenError(err)
dumpValue(res)
},
}
var oauthPut = &cobra.Command{
Use: "put [# network] [# clientid] [# clientsecret]",
Short: "add a new oauth provider with the given data",
Long: "some predefined networks only require the clientid/secret, others need more data so use the flags to add more data",
Run: func(cmd *cobra.Command, args []string) {
if len(args) < 3 {
cmd.Usage()
os.Exit(1)
}
reg := oauth.AuthRegistration{
Network: args[0],
ClientId: args[1],
ClientSecret: args[2],
Scopes: scopes,
AuthUrl: authUrl,
AccessTokenUrl: accessTokenUrl,
UserinfoUrl: userinfoUrl,
PathId: pathid,
PathName: pathname,
PathPicture: pathpicture,
PathCover: pathcover,
}
c := newCli()
exitWhenError(c.putProvider(reg))
},
}
var oauthDelete = &cobra.Command{
Use: "delete [# network]",
Short: "delete the provider for the given network",
Long: "delete the provider for the given network",
Run: func(cmd *cobra.Command, args []string) {
if len(args) < 1 {
cmd.Usage()
os.Exit(1)
}
c := newCli()
exitWhenError(c.delProvider(args[0]))
},
}
func init() {
oauthPut.Flags().StringVar(&loginscope, "loginscope", "", "the scopes to use on the client for authentication")
oauthPut.Flags().StringVar(&scopes, "scopes", "", "the scopes to use on the server")
oauthPut.Flags().StringVar(&authUrl, "authurl", "", "the authorization url")
oauthPut.Flags().StringVar(&accessTokenUrl, "accesstokenurl", "", "the url to get an access token")
oauthPut.Flags().StringVar(&userinfoUrl, "userinfourl", "", "the url to get the user account information")
oauthPut.Flags().StringVar(&pathid, "id", "", "a json pathspec for the id value")
oauthPut.Flags().StringVar(&pathname, "name", "", "a json pathspec for the name value")
oauthPut.Flags().StringVar(&pathpicture, "picture", "", "a json pathspec for the picture value")
oauthPut.Flags().StringVar(&pathcover, "cover", "", "a json pathspec for the cover value")
oauthCmd.AddCommand(oauthList, oauthPut, oauthDelete)
}