All Downloads are FREE. Search and download functionalities are using the official Maven repository.

pl.wrzasq.commons.client.interceptor.BearerTokenAuthorizer Maven / Gradle / Ivy

There is a newer version: 2.0.10
Show newest version
// Generated by delombok at Thu Apr 04 00:08:20 UTC 2019
/*
 * This file is part of the pl.wrzasq.commons.
 *
 * @license http://mit-license.org/ The MIT license
 * @copyright 2017, 2019 © by Rafał Wrzeszcz - Wrzasq.pl.
 */
package pl.wrzasq.commons.client.interceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.http.HttpHeaders;

/**
 * Feign request interceptor that injects custom HTTP authorization with Bearer token.
 */
public class BearerTokenAuthorizer implements RequestInterceptor {
    /**
     * Bearer token prefix.
     */
    private static final String TYPE_BEARER = "Bearer ";
    /**
     * HTTP access token..
     */
    private String token;

    /**
     * {@inheritDoc}
     */
    @Override
    public void apply(RequestTemplate requestTemplate) {
        // set the same value as incoming request to execute requests on behalf of the user
        requestTemplate.header(HttpHeaders.AUTHORIZATION, BearerTokenAuthorizer.TYPE_BEARER + this.token);
    }

    @SuppressWarnings("all")
    @lombok.Generated
    public BearerTokenAuthorizer(final String token) {
        this.token = token;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy