Skip to content

Commit 4d763fe

Browse files
authored
Add documentation for common Auth headers support (#28)
1 parent e3a9ccf commit 4d763fe

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,34 @@ func TestSome(t *testing.T) {
121121
}
122122
```
123123

124+
## Support for Authentication Schemes
125+
126+
The library provides support for common authentication schemes, i.e.: Basic Authentication, API Token Authentication, Bearer Authentication, Digest Access Authentication.
127+
All of them are equivalent to manually specifying the "Authorization" header value with the appropriate prefix.
128+
E.g. `WithBearerToken(wiremock.EqualTo("token123")).` works the same as `WithHeader("Authorization", wiremock.EqualTo("Bearer token123")).`.
129+
130+
### Example of usage
131+
132+
```go
133+
134+
basicAuthStub := wiremock.Get(wiremock.URLPathEqualTo("/basic")).
135+
WithBasicAuth("username", "password"). // same as: WithHeader("Authorization", wiremock.EqualTo("Basic dXNlcm5hbWU6cGFzc3dvcmQ=")).
136+
WillReturnResponse(wiremock.NewResponse().WithStatus(http.StatusOK))
137+
138+
bearerTokenStub := wiremock.Get(wiremock.URLPathEqualTo("/bearer")).
139+
WithBearerToken(wiremock.Matching("^\\S+abc\\S+$")). // same as: WithHeader("Authorization", wiremock.Matching("^Bearer \\S+abc\\S+$")).
140+
WillReturnResponse(wiremock.NewResponse().WithStatus(http.StatusOK))
141+
142+
apiTokenStub := wiremock.Get(wiremock.URLPathEqualTo("/token")).
143+
WithAuthToken(wiremock.StartsWith("myToken123")). // same as: WithHeader("Authorization", wiremock.StartsWith("Token myToken123")).
144+
WillReturnResponse(wiremock.NewResponse().WithStatus(http.StatusOK))
145+
146+
digestAuthStub := wiremock.Get(wiremock.URLPathEqualTo("/digest")).
147+
WithDigestAuth(wiremock.Contains("realm")). // same as: WithHeader("Authorization", wiremock.StartsWith("Digest ").And(Contains("realm"))).
148+
WillReturnResponse(wiremock.NewResponse().WithStatus(http.StatusOK))
149+
150+
```
151+
124152
## License
125153

126154
[MIT License](./LICENSE)

0 commit comments

Comments
 (0)