@@ -33,7 +33,39 @@ Enabling this feature will add listeners to the following four routes at the pub
33
33
34
34
If OpenID Connect Dynamic Client Registration is enabled, registering a new OAuth2 Client is as simple as :
35
35
36
+ ` ` ` ` mdx-code-block
37
+ import Tabs from '@theme/Tabs'
38
+ import TabItem from '@theme/TabItem'
39
+
40
+ <Tabs
41
+ defaultValue="go"
42
+ values={[
43
+ {label: 'Go', value: 'go'},
44
+ {label: 'HTTP', value: 'http'},
45
+ ]}>
46
+ <TabItem value="go">
47
+
48
+ ` ` ` go
49
+ import ory "github.com/ory/client-go"
50
+
51
+ func newSDK(port int, host string) *ory.APIClient {
52
+ conf := ory.NewConfiguration()
53
+ conf.Servers = ory.ServerConfigurations{ory.ServerConfiguration{URL: "https://<slug>.projects.oryapis.com"}}
54
+ return ory.NewAPIClient(conf)
55
+ }
56
+
57
+ func createDynamicClient() (*ory.OAuth2Client, error) {
58
+ c, _, err := newSDK().V0Alpha2.
59
+ DynamicClientRegistrationCreateOAuth2Client(context.Background()).
60
+ OAuth2Client(ory.OAuth2Client{ /* ClientName: "..." */ }).Execute()
61
+ return c, err
62
+ }
36
63
` ` `
64
+
65
+ </TabItem>
66
+ <TabItem value="http">
67
+
68
+ ` ` ` shell
37
69
POST /oauth2/register
38
70
Content-Type: application/json
39
71
@@ -44,6 +76,10 @@ Content-Type: application/json
44
76
}
45
77
` ` `
46
78
79
+ </TabItem>
80
+ </Tabs>
81
+ ````
82
+
47
83
:::note
48
84
49
85
The `registration_access_token` will only be sent once! You need to store this token in a secure location. This token will be used
@@ -62,7 +98,37 @@ also not be read using OpenID Connect Dynamic Client Registration endpoints!
62
98
The `POST` endpoint requires the client to authenticate with the `registration_access_token` regardless of the
63
99
` token_endpoint_auth_method` . It can be used to update the OAuth2 Client.
64
100
101
+ ` ` ` ` mdx-code-block
102
+ <Tabs
103
+ defaultValue="go"
104
+ values={[
105
+ {label: 'Go', value: 'go'},
106
+ {label: 'HTTP', value: 'http'},
107
+ ]}>
108
+ <TabItem value="go">
109
+
110
+ ` ` ` go
111
+ // ...
112
+ func updateDynamicClient(client *ory.OAuth2Client) (*ory.OAuth2Client, error) {
113
+ c, _, err := newSDK(publicPort, host).V0Alpha2.
114
+ DynamicClientRegistrationUpdateOAuth2Client(
115
+ context.WithValue(context.Background(), hydra.ContextAccessToken, *client.RegistrationAccessToken),
116
+ *client.ClientId,
117
+ ).
118
+ OAuth2Client(*client).
119
+ Execute()
120
+
121
+ // Don't forget to store the update ` registration_access_token`!
122
+ // newToken := *c.RegistrationAccessToken
123
+
124
+ return c, err
125
+ }
65
126
```
127
+
128
+ </TabItem >
129
+ <TabItem value = " http" >
130
+
131
+ ``` shell
66
132
PUT /oauth2/register/{client_id}
67
133
Authorization: Bearer < registration_access_token>
68
134
Content-Type: application/json
@@ -73,6 +139,10 @@ Content-Type: application/json
73
139
}
74
140
```
75
141
142
+ </TabItem >
143
+ </Tabs >
144
+ ````
145
+
76
146
The response will include the updated OAuth2 Client.
77
147
78
148
:::note
@@ -94,7 +164,31 @@ When updating the OAuth2 Client, the server will respond with a new registration
94
164
The `GET` endpoint requires the client to authenticate with the `registration_access_token` regardless of the
95
165
`token_endpoint_auth_method`. It can be used to retrieve the OAuth2 Client.
96
166
167
+ ````mdx-code-block
168
+ <Tabs
169
+ defaultValue="go"
170
+ values={[
171
+ {label: 'Go', value: 'go'},
172
+ {label: 'HTTP', value: 'http'},
173
+ ]}>
174
+ <TabItem value="go">
175
+
176
+ ```go
177
+ // ...
178
+ func getDynamicClient(client *ory.OAuth2Client) (*ory.OAuth2Client, error) {
179
+ c, _, err := newSDK(publicPort, host).V0Alpha2.
180
+ DynamicClientRegistrationGetOAuth2Client(
181
+ context.WithValue(context.Background(), hydra.ContextAccessToken, *client.RegistrationAccessToken),
182
+ *client.ClientId,
183
+ ).Execute()
184
+ return c, err
185
+ }
97
186
```
187
+
188
+ </TabItem>
189
+ <TabItem value="http">
190
+
191
+ ```shell
98
192
GET /oauth2/register/{client_id}
99
193
Authorization: Bearer <registration_access_token>
100
194
Content-Type: application/json
@@ -105,12 +199,44 @@ Content-Type: application/json
105
199
}
106
200
```
107
201
202
+ </TabItem>
203
+ </Tabs>
204
+ ````
205
+
108
206
## Delete OAuth2 & OpenID Connect Clients
109
207
110
208
The ` DELETE ` endpoint requires the client to authenticate with the ` registration_access_token ` regardless of the
111
209
` token_endpoint_auth_method ` . It can be used to delete the OAuth2 Client.
112
210
211
+ ```` mdx-code-block
212
+ <Tabs
213
+ defaultValue="go"
214
+ values={[
215
+ {label: 'Go', value: 'go'},
216
+ {label: 'HTTP', value: 'http'},
217
+ ]}>
218
+ <TabItem value="go">
219
+
220
+ ```go
221
+ // ...
222
+ func deleteDynamicClient(client *ory.OAuth2Client) (error) {
223
+ _, err := newSDK(publicPort, host).V0Alpha2.
224
+ DynamicClientRegistrationDeleteOAuth2Client(
225
+ context.WithValue(context.Background(), hydra.ContextAccessToken, *client.RegistrationAccessToken),
226
+ *client.ClientId,
227
+ ).Execute()
228
+ return err
229
+ }
113
230
```
231
+
232
+ </TabItem>
233
+ <TabItem value="http">
234
+
235
+ ```shell
114
236
DELETE /oauth2/register/{client_id}
115
237
Authorization: Bearer <registration_access_token>
116
238
```
239
+
240
+ </TabItem>
241
+ </Tabs>
242
+ ````
0 commit comments