Commit 268fd75
feat: Add OAuth support for HTTP Sync (#1791)
<!-- Please use this template for your pull request. -->
<!-- Please use the sections that you need and delete other sections -->
## This PR
- adds support for OAuth in the HTTP Sync
### Related Issues
<!-- add here the GitHub issue that this PR resolves if applicable -->
Addresses #1785
### Notes
Properly testing this via unit tests is not possible. The HTTP Sync is
built by the `syncbuilder` pkg. This entails that testing any behavior
of the HTTP Sync can only be possible as part of the `syncbuilder`
module, which IMHO doesn't make much sense.
### Follow-up Tasks
Add documentation for the new properties used in the HTTP Sync.
Available here: #1805
### How to test
<!-- if applicable, add testing instructions under this section -->
Manually create a small mockup server that handles OAuth requests
```go
func (h *OAuthHandler) Authorize(w http.ResponseWriter, r *http.Request) {
reqDump, _ := httputil.DumpRequest(r, true)
fmt.Printf("GOT OAUTH REQUEST:\n%s", string(reqDump))
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/x-www-form-urlencoded")
w.Write([]byte("access_token=mocktoken&scope=mockscope&token_type=bearer"))
}
```
Afterwards, start flagd pointing to the mockup server:
```
go run main.go start --sources='[{ "uri": "http://localhost:8180/flags", "provider": "http", "interval": 1, "bearerToken": "it-will-be-overridden", "oauthConfig": { "clientID": "test", "clientSecret": "test", "tokenUrl": "http://localhost:8180/oauth" }}]'
```
The HTTP request to `http://localhost:8180/flags` will contain the HTTP
Header `Authorization: Bearer mocktoken`.
---------
Signed-off-by: Todd Baert <[email protected]>
Signed-off-by: Giovanni Liva <[email protected]>
Signed-off-by: Simon Schrottner <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Todd Baert <[email protected]>
Co-authored-by: Simon Schrottner <[email protected]>
Co-authored-by: chrfwow <[email protected]>1 parent 5ff38b4 commit 268fd75
File tree
5 files changed
+532
-99
lines changed- core/pkg/sync
- builder
- http
5 files changed
+532
-99
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | 5 | | |
7 | 6 | | |
8 | | - | |
9 | 7 | | |
10 | 8 | | |
11 | 9 | | |
| |||
112 | 110 | | |
113 | 111 | | |
114 | 112 | | |
115 | | - | |
| 113 | + | |
116 | 114 | | |
117 | 115 | | |
118 | 116 | | |
| |||
186 | 184 | | |
187 | 185 | | |
188 | 186 | | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | 187 | | |
213 | 188 | | |
214 | 189 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
0 commit comments