Skip to content
This repository was archived by the owner on Jun 21, 2022. It is now read-only.

Commit 760b560

Browse files
committed
Added documentation for bearer auth
1 parent 25c2655 commit 760b560

File tree

1 file changed

+55
-12
lines changed

1 file changed

+55
-12
lines changed

README.md

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ Now head over to the *frontend* served under **http://localhost:8070/** (routed
116116

117117
### Test with other tools
118118

119+
All values in *doubled curly brackets ({{})* must be replaced with the actual value, including the brackets!
120+
119121
#### RSocket
120122

121123
For RSocket development I used [RSC](https://github.com/making/rsc) installed using:
@@ -130,44 +132,85 @@ brew install making/tap/rsc
130132

131133
```shell
132134
# Basic
133-
$ rsc --stream --route=orders.all --sm simple:user:password --smmt MESSAGE_RSOCKET_AUTHENTICATION --debug ws://localhost:8070/server/rsocket
134-
$ rsc --stream --route=orders.lotr --sm simple:user:password --smmt MESSAGE_RSOCKET_AUTHENTICATION --debug ws://localhost:8070/server/rsocket
135-
$ rsc --stream --route=orders.got --sm simple:user:password --smmt MESSAGE_RSOCKET_AUTHENTICATION --debug ws://localhost:8070/server/rsocket
135+
$ rsc --stream --route=orders.all --sm simple:{{user}}:{{password}} --smmt MESSAGE_RSOCKET_AUTHENTICATION --debug ws://localhost:8070/server/rsocket
136+
$ rsc --stream --route=orders.lotr --sm simple:{{user}}:{{password}} --smmt MESSAGE_RSOCKET_AUTHENTICATION --debug ws://localhost:8070/server/rsocket
137+
$ rsc --stream --route=orders.got --sm simple:{{user}}:{{password}} --smmt MESSAGE_RSOCKET_AUTHENTICATION --debug ws://localhost:8070/server/rsocket
136138

137139
# With data (payload)
138-
$ rsc --stream --route=orders.all --sm simple:user:password --smmt MESSAGE_RSOCKET_AUTHENTICATION --debug --data='{"rscclient":"request"}' ws://localhost:8070/server/rsocket
140+
$ rsc --stream --route=orders.all --sm simple:{{user}}:{{password}} --smmt MESSAGE_RSOCKET_AUTHENTICATION --debug --data='{"rscclient":"request"}' ws://localhost:8070/server/rsocket
139141

140142
# With metadata
141-
$ rsc --stream --route=orders.all --sm simple:user:password --smmt MESSAGE_RSOCKET_AUTHENTICATION --debug --metadata='{"data":"custom metadata value from rsc"}' ws://localhost:8070/server/rsocket
143+
$ rsc --stream --route=orders.all --sm simple:{{user}}:{{password}} --smmt MESSAGE_RSOCKET_AUTHENTICATION --debug --metadata='{"data":"custom metadata value from rsc"}' ws://localhost:8070/server/rsocket
142144
```
143145

144146
##### KeyCloak
145147

146-
Needs to be added...
148+
First we need to get an *access_token* for *bearer auth*, [see this](#get-access-token)
149+
150+
```shell
151+
# Basic
152+
$ rsc --stream --route=orders.all --sm "bearer:{{access_token}}" --smmt MESSAGE_RSOCKET_AUTHENTICATION --debug ws://localhost:8070/server/rsocket
153+
$ rsc --stream --route=orders.lotr --sm "bearer:{{access_token}}" --smmt MESSAGE_RSOCKET_AUTHENTICATION --debug ws://localhost:8070/server/rsocket
154+
$ rsc --stream --route=orders.got --sm "bearer:{{access_token}}" --smmt MESSAGE_RSOCKET_AUTHENTICATION --debug ws://localhost:8070/server/rsocket
155+
156+
# With data (payload)
157+
$ rsc --stream --route=orders.all --sm "bearer:{{access_token}}" --smmt MESSAGE_RSOCKET_AUTHENTICATION --debug --data='{"rscclient":"request"}' ws://localhost:8070/server/rsocket
158+
159+
# With metadata
160+
$ rsc --stream --route=orders.all --sm "bearer:{{access_token}}" --smmt MESSAGE_RSOCKET_AUTHENTICATION --debug --metadata='{"data":"custom metadata value from rsc"}' ws://localhost:8070/server/rsocket
161+
```
147162

148163
#### HTTP
149164

150165
To retrieve the stream using *HTTP* I used [HTTPIE](https://httpie.io/) using:
151166

152167
##### SpringSecurity
153168

169+
Retrieve orders:
170+
154171
````shell
155-
http :8070/server/orders --stream --auth "user:password"
172+
http --stream :8070/server/orders --auth "{{user}}:{{password}}"
156173
````
157174

158-
Use *HTTPie* to create orders:
175+
Create orders:
159176

160177
```shell
161178
# Random
162-
http :8070/server/orders/new --auth "user:password"
179+
http :8070/server/orders/new --auth "{{user}}:{{password}}"
163180
# Specific
164-
http :8070/server/orders/new kind==lotr --auth "user:password"
165-
http :8070/server/orders/new kind==got --auth "user:password"
181+
http :8070/server/orders/new kind==lotr --auth "{{user}}:{{password}}"
182+
http :8070/server/orders/new kind==got --auth "{{user}}:{{password}}"
166183
```
167184

185+
http --stream :8070/server/orders Authorization:"Bearer {{access_token}}"
186+
168187
##### KeyCloak
169188

170-
Needs to be added...
189+
First we need to get an *access_token* for *bearer auth*, [see this](#get-access-token)
190+
191+
````shell
192+
http --stream :8070/server/orders Authorization:"Bearer {{access_token}}"
193+
````
194+
195+
Create orders:
196+
197+
```shell
198+
# Random
199+
http :8070/server/orders/new Authorization:"Bearer {{access_token}}"
200+
# Specific
201+
http :8070/server/orders/new kind==lotr Authorization:"Bearer {{access_token}}"
202+
http :8070/server/orders/new kind==got Authorization:"Bearer {{access_token}}"
203+
```
204+
205+
### Get KeyCloak AccessToken <span id="get-access-token"><span>
206+
207+
To directly extract the token from the JSON response [JQ](https://github.com/stedolan/jq) is used.
208+
209+
```shell
210+
http -f :8060/auth/realms/RSOCKET/protocol/openid-connect/token client_id=gateway username={{user}} password={{password}} grant_type=password client_secret=059fa1a6-b94f-42a1-81c8-210acfe6f299 | jq .access_token
211+
```
212+
213+
Now this token can be used for *bearer auth*.
171214

172215
## Next up
173216

0 commit comments

Comments
 (0)