Reputation: 135
Can I use Spring RestDocs to document APIs when the authorization mode is bearer
?
A pointer to a simple example would be appreciated, it doesn't seem the be available on the Spring RestDocs pages.
Thanks
Upvotes: 0
Views: 212
Reputation: 135
It's actually very simple.
First obtain a bearer-token and encode it so you can use it as a string.
Next add the header to your call, like:
.header("Authorization", "Bearer " + "your encoded token")
TestClient.put().uri("/v1/some_endpoint/foos")
.header("Authorization", "Bearer " + "your encoded token")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.body(BodyInserters.fromValue("{"pay":"load"}))
.exchange()
.expectStatus().isOk();
Upvotes: 0