forked from zemirco/keycloak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclients.go
147 lines (125 loc) · 5.6 KB
/
clients.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package keycloak
import (
"context"
"fmt"
"net/http"
)
// ClientsService handles communication with the client related methods of the Keycloak API.
type ClientsService service
// Client represents a Keycloak client.
//
// https://github.com/keycloak/keycloak/blob/master/core/src/main/java/org/keycloak/representations/idm/ClientRepresentation.java
type Client struct {
ID *string `json:"id,omitempty"`
ClientID *string `json:"clientId,omitempty"`
Name *string `json:"name,omitempty"`
RootURL *string `json:"rootUrl,omitempty"`
BaseURL *string `json:"baseUrl,omitempty"`
SurrogateAuthRequired *bool `json:"surrogateAuthRequired,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
AlwaysDisplayInConsole *bool `json:"alwaysDisplayInConsole,omitempty"`
ClientAuthenticatorType *string `json:"clientAuthenticatorType,omitempty"`
DefaultRoles []string `json:"defaultRoles,omitempty"`
RedirectUris []string `json:"redirectUris,omitempty"`
WebOrigins []string `json:"webOrigins,omitempty"`
NotBefore *int `json:"notBefore,omitempty"`
BearerOnly *bool `json:"bearerOnly,omitempty"`
ConsentRequired *bool `json:"consentRequired,omitempty"`
StandardFlowEnabled *bool `json:"standardFlowEnabled,omitempty"`
ImplicitFlowEnabled *bool `json:"implicitFlowEnabled,omitempty"`
DirectAccessGrantsEnabled *bool `json:"directAccessGrantsEnabled,omitempty"`
ServiceAccountsEnabled *bool `json:"serviceAccountsEnabled,omitempty"`
AuthorizationServicesEnabled *bool `json:"authorizationServicesEnabled,omitempty"`
PublicClient *bool `json:"publicClient,omitempty"`
FrontchannelLogout *bool `json:"frontchannelLogout,omitempty"`
Protocol *string `json:"protocol,omitempty"`
Attributes *map[string]string `json:"attributes,omitempty"`
AuthenticationFlowBindingOverrides *map[string]string `json:"authenticationFlowBindingOverrides,omitempty"`
FullScopeAllowed *bool `json:"fullScopeAllowed,omitempty"`
NodeReRegistrationTimeout *int `json:"nodeReRegistrationTimeout,omitempty"`
DefaultClientScopes []string `json:"defaultClientScopes,omitempty"`
OptionalClientScopes []string `json:"optionalClientScopes,omitempty"`
Access *map[string]bool `json:"access,omitempty"`
}
// List all clients in realm.
func (s *ClientsService) List(ctx context.Context, realm string) ([]*Client, *http.Response, error) {
u := fmt.Sprintf("admin/realms/%s/clients", realm)
req, err := s.keycloak.NewRequest(http.MethodGet, u, nil)
if err != nil {
return nil, nil, err
}
var clients []*Client
res, err := s.keycloak.Do(ctx, req, &clients)
if err != nil {
return nil, nil, err
}
return clients, res, nil
}
// Create a new client.
func (s *ClientsService) Create(ctx context.Context, realm string, client *Client) (*http.Response, error) {
u := fmt.Sprintf("admin/realms/%s/clients", realm)
req, err := s.keycloak.NewRequest(http.MethodPost, u, client)
if err != nil {
return nil, err
}
return s.keycloak.Do(ctx, req, nil)
}
// Update a new client.
func (s *ClientsService) Update(ctx context.Context, realm string, client *Client) (*http.Response, error) {
u := fmt.Sprintf("admin/realms/%s/clients/%s", realm, *client.ID)
req, err := s.keycloak.NewRequest(http.MethodPut, u, client)
if err != nil {
return nil, err
}
return s.keycloak.Do(ctx, req, nil)
}
// Get client.
func (s *ClientsService) Get(ctx context.Context, realm, id string) (*Client, *http.Response, error) {
u := fmt.Sprintf("admin/realms/%s/clients/%s", realm, id)
req, err := s.keycloak.NewRequest(http.MethodGet, u, nil)
if err != nil {
return nil, nil, err
}
var client Client
res, err := s.keycloak.Do(ctx, req, &client)
if err != nil {
return nil, nil, err
}
return &client, res, nil
}
// Delete ...
func (s *ClientsService) Delete() {
}
// GetSecret gets client secret.
func (s *ClientsService) GetSecret(ctx context.Context, realm, id string) (*Credential, *http.Response, error) {
u := fmt.Sprintf("admin/realms/%s/clients/%s/client-secret", realm, id)
req, err := s.keycloak.NewRequest(http.MethodGet, u, nil)
if err != nil {
return nil, nil, err
}
var credential Credential
res, err := s.keycloak.Do(ctx, req, &credential)
if err != nil {
return nil, nil, err
}
return &credential, res, nil
}
// CreateSecret generates a new secret for the client
func (s *ClientsService) CreateSecret(ctx context.Context, realm, id string) (*Credential, *http.Response, error) {
u := fmt.Sprintf("admin/realms/%s/clients/%s/client-secret", realm, id)
req, err := s.keycloak.NewRequest(http.MethodPost, u, nil)
if err != nil {
return nil, nil, err
}
var credential Credential
res, err := s.keycloak.Do(ctx, req, &credential)
if err != nil {
return nil, nil, err
}
return &credential, res, nil
}
// Options ...
type Options struct {
First int `url:"first,omitempty"`
Max string `url:"max,omitempty"`
}