Skip to content

Commit 69a4848

Browse files
kostya05983jzheaux
authored andcommitted
BearerTokenResolver Docs
Fixes gh-6254
1 parent 2e2554a commit 69a4848

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

docs/manual/src/docs/asciidoc/_includes/reactive/oauth2/access-token.adoc

+43
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,46 @@ SecurityWebFilterChain configure(ServerHttpSecurity http) throws Exception {
3333
----
3434

3535
You can now leverage Spring Security's <<webclient>> or <<webflux-roac,@RegisteredOAuth2AuthorizedClient>> support to obtain and use the access token.
36+
37+
== BearerTokenResolver
38+
39+
With interface BearerTokenResolver you can provide a strategy to resolve a bearer token.
40+
41+
The interface provides the next method:
42+
43+
[source,java]
44+
----
45+
/**
46+
* Resolve any <a href="https://tools.ietf.org/html/rfc6750#section-1.2" target="_blank">Bearer Token</a>
47+
* value from the request.
48+
*
49+
* @param request the request
50+
* @return the Bearer Token value or {@code null} if none found
51+
* @throws OAuth2AuthenticationException if the found token is invalid
52+
*/
53+
String resolve(HttpServletRequest request);
54+
----
55+
56+
In code base, you can find two implementation of this interface:
57+
HeaderBearerTokenResolver and DefaultBearerTokenResolver (based on RFC 6750).
58+
59+
Below you can see HeaderBearerTokenResolver, it takes a bearer token from request by header
60+
which was passed in constructor
61+
62+
[source,java]
63+
----
64+
public class HeaderBearerTokenResolver implements BearerTokenResolver {
65+
66+
private String header;
67+
68+
public HeaderBearerTokenResolver(String header) {
69+
Assert.hasText(header, "header cannot be empty");
70+
this.header = header;
71+
}
72+
73+
@Override
74+
public String resolve(HttpServletRequest request) {
75+
return request.getHeader(this.header);
76+
}
77+
}
78+
----

0 commit comments

Comments
 (0)