V
V
vitya_brodov2022-04-04 06:03:34
Java
vitya_brodov, 2022-04-04 06:03:34

How to deal with authorization in WebClient Spring boot?

I have a third party API that I want to send a post request to.
But in order to make some requests, you need to log in (Basic auth).
Question: How can I do authorization using WebClient?

code:

public Response checkLink(PaymentLink dto) {
        String salt = UUID.randomUUID().toString();
        String signature = HmacEncodeUtil.hmacEncode(secretKey, checkLinkUrl, dto.toString(), salt);

        return webClient.post()
                .uri(checkLinkUrl)
                .header("x-psp-api-salt", salt)
                .header("x-psp-api-signature", signature)
                .bodyValue(dto)
                .retrieve()
                .bodyToMono(Response.class)
                .block();
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Roo, 2022-04-04
@vitya_brodov

Vitya, well, such an elementary question could have been Googled.
Basic access authentication :
“In basic HTTP authentication, a request contains a header field in the form of Authorization: Basic , where credentials is the Base64 encoding of ID and password joined by a single colon :
“ you need to add the header: Authorization: Basic <credentials>, where credentials are the login and password encrypted in base64 and separated by a colon.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question