quarkus:如何在其余客户端上提供令牌

时间:2020-03-26 21:05:43

标签: rest security testing token quarkus

在单元测试中,我通过REST客户端(通过@RegisterRestClient带注释的接口)调用@Authenticated终结点。如何在REST调用中提供令牌?

1 个答案:

答案 0 :(得分:0)

界面:

import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

@RegisterRestClient
public interface MyAuthenticatedService {

    @GET
    public void myAuthenticatedCall(@HeaderParam("Authorization") String token);

}

通话本身:

import javax.inject.Inject;
import org.eclipse.microprofile.rest.client.inject.RestClient;

public class FoobarService {

    @Inject
    @RestClient
    MyAuthenticatedService myService;

    public void foobar(String token) {
        myService.myAuthenticatedCall("Bearer " + token); // beware of the space
    }
}