OpenAI-J/client/src/main/java/com/theokanning/openai/AuthenticationInterceptor.java
Theo Kanning 00fa073446 Update package names
This matches the library groupId and makes it clear that this is not an OpenAI product
2020-10-05 17:44:18 -05:00

29 lines
672 B
Java

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);
}
}