OpenAI-J/openai-j-client/src/main/java/com/ossez/openai/AuthenticationInterceptor.java

29 lines
666 B
Java
Raw Normal View History

package com.ossez.openai;
2023-01-06 12:36:47 -05:00
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);
}
}