This repository has been archived by the owner on Oct 20, 2021. It is now read-only.
/
register_client.go
79 lines (65 loc) · 1.79 KB
/
register_client.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
package main
import (
"fmt"
"log"
"os"
"strconv"
"code.cloudfoundry.org/clock"
"code.cloudfoundry.org/lager"
client "code.cloudfoundry.org/uaa-go-client"
"code.cloudfoundry.org/uaa-go-client/config"
"code.cloudfoundry.org/uaa-go-client/schema"
)
func main() {
var (
err error
uaaClient client.Client
// token *schema.Token
)
if len(os.Args) < 6 {
fmt.Printf("Usage: <admin-client-name> <admin-client-secret> <uaa-url> <skip-verification> <new-client-id>\n\n")
fmt.Printf("For example: admin-client-name admin-client-secret https://uaa.service.cf.internal:8443 true new-client-id\n")
return
}
skip, err := strconv.ParseBool(os.Args[4])
if err != nil {
log.Fatal(err)
os.Exit(1)
}
cfg := &config.Config{
ClientName: os.Args[1],
ClientSecret: os.Args[2],
UaaEndpoint: os.Args[3],
SkipVerification: skip,
}
logger := lager.NewLogger("test")
clock := clock.NewClock()
uaaClient, err = client.NewClient(logger, cfg, clock)
if err != nil {
log.Fatal(err)
os.Exit(1)
}
fmt.Printf("Connecting to: %s ...\n", cfg.UaaEndpoint)
// token, err = uaaClient.FetchToken(true)
// if err != nil {
// log.Fatal(err)
// os.Exit(1)
// }
oauthClient := &schema.OauthClient{
ClientId: os.Args[5],
Name: "the new client",
ClientSecret: "secret",
Scope: []string{"uaa.none"},
ResourceIds: []string{"none"},
Authorities: []string{"openid"},
AuthorizedGrantTypes: []string{"client_credentials"},
AccessTokenValidity: 10000,
RedirectUri: []string{"http://example.com"},
}
receivedOauthClient, err := uaaClient.RegisterOauthClient(oauthClient)
if err != nil {
log.Fatal(err)
os.Exit(1)
}
fmt.Printf("Received Oauth Client:%+v\n", receivedOauthClient)
}