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

com.theokanning.openai.AuthenticationInterceptor Maven / Gradle / Ivy

package com.theokanning.openai;

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

import java.io.IOException;

/**
 * OkHttp Interceptor that adds an authorization token header
 */
public class AuthenticationInterceptor implements Interceptor {

    private final String token;

    AuthenticationInterceptor(String token) {
        this.token = token;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request()
                .newBuilder()
                .header("Authorization", "Bearer " + token)
                .build();
        return chain.proceed(request);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy