Skip to content

Instantly share code, notes, and snippets.

@janakagamini
janakagamini / FirebaseUserIdTokenInterceptor.java
Last active June 4, 2021 06:36
A simple Interceptor to include a Firebase user's id token in all requests. Useful for authenticating Firebase users with a custom backend. See: https://firebase.google.com/docs/auth/admin/verify-id-tokens#retrieve_id_tokens_on_clients)
public class FirebaseUserIdTokenInterceptor implements Interceptor {
// Custom header for passing ID token in request.
private static final String X_FIREBASE_ID_TOKEN = "YOUR-CUSTOM-HEADER";
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
try {