OAuth2AuthorizedClient

OAuth2AuthorizedClient

使用经典的MVC风格的RestController,很容易获得OAuth2AuthorizedClient,我要做的就是:

@GetMapping("/foo")
public Foo getFoo(@RegisteredOAuth2AuthorizedClient OAuth2AuthorizedClient client){
    return new Foo(client.getPrincipalName());
}


但是,借助Webflux的功能端点,我如何以类似的方式访问OAuth2AuthorizedClient?

编辑:

更清楚地说,我知道被动式方法与非被动式方法相同。我很好奇的是如何从Webflux的功能端点访问OAuth2AuthorizedClient:

PersonRepository repository = ...
PersonHandler handler = new PersonHandler(repository);

RouterFunction<ServerResponse> route = route()
    .GET("/person/{id}", accept(APPLICATION_JSON), handler::getPerson)
    .GET("/person", accept(APPLICATION_JSON), handler::listPeople)
    .POST("/person", handler::createPerson)
    .build();


public class PersonHandler {

    // ...

    public Mono<ServerResponse> listPeople(ServerRequest request) {
        // ...
    }

    public Mono<ServerResponse> createPerson(ServerRequest request) {
        // ...
    }

    public Mono<ServerResponse> getPerson(ServerRequest request) {
        // ...
    }
}


例如,在createPerson方法中,如何访问OAuth2AuthorizedClient?

最佳答案

看起来它的工作方式与非反应性方法相同。

请看一下:


docs:
https://docs.spring.io/spring-security/site/docs/5.1.0.RELEASE/reference/html/webflux-roac.html
例如:https://github.com/spring-projects/spring-security/tree/5.1.0.RELEASE/samples/boot/oauth2webclient-webflux

09-25 20:41