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

com.finbourne.notifications.extensions.AuthenticationInterceptor Maven / Gradle / Ivy

There is a newer version: 2.0.68
Show newest version
package com.finbourne.notifications.extensions;

import java.io.IOException;

import com.finbourne.notifications.ApiException;
import com.finbourne.notifications.extensions.auth.FinbourneTokenException;
import com.finbourne.notifications.extensions.auth.RefreshingTokenProvider;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class AuthenticationInterceptor implements Interceptor {
    private RefreshingTokenProvider tokenProvider;

    public AuthenticationInterceptor(RefreshingTokenProvider tokenProvider) {
        this.tokenProvider = tokenProvider;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        try {
            Request request = chain.request()
                    .newBuilder()
                    .header("Authorization", "Bearer " + this.tokenProvider.get().getAccessToken())
                    .build();
            return chain.proceed(request);
        } catch (FinbourneTokenException e) {
            throw new IOException(e);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy