class AuthorizationInterceptor implements Interceptor {

    private static final long expireMillis = 1000 * 60 * 30;
    private static final String id = "HS256";
    private static final String jcaName = "HmacSHA256";
    private static final MacAlgorithm macAlgorithm;

    static {
        try {
            //create a custom MacAlgorithm with a custom minKeyBitLength
            int minKeyBitLength = 128;
            Class<?> c = Class.forName("io.jsonwebtoken.impl.security.DefaultMacAlgorithm");
            Constructor<?> ctor = c.getDeclaredConstructor(String.class, String.class, int.class);
            ctor.setAccessible(true);
            macAlgorithm = (MacAlgorithm) ctor.newInstance(id, jcaName, minKeyBitLength);
        } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException |
                 InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }

    private final String apiKey;
    private final Cache<String, String> cache = CacheBuilder.newBuilder()
            .expireAfterWrite(Duration.ofMillis(expireMillis))
            .build();


    public AuthorizationInterceptor(String apiKey) {
        this.apiKey = apiKey;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        String token = getOrDefault(cache.getIfPresent(this.apiKey), generateToken());
        Request request = chain.request()
                .newBuilder()
                .addHeader("Authorization", "Bearer " + token)
                .removeHeader("Accept")
                .build();
        return chain.proceed(request);
    }

    private String generateToken() {<FILL_FUNCTION_BODY>}

}

        String[] apiKeyParts = this.apiKey.split("\\.");
        String keyId = apiKeyParts[0];
        String secret = apiKeyParts[1];
        Map<String, Object> payload = new HashMap<>(3);
        payload.put("api_key", keyId);
        payload.put("exp", currentTimeMillis() + expireMillis);
        payload.put("timestamp", currentTimeMillis());

        String token = Jwts.builder()
                .header()
                .add("alg", id)
                .add("sign_type", "SIGN")
                .and()
                .content(Json.toJson(payload))
                .signWith(new SecretKeySpec(secret.getBytes(UTF_8), jcaName), macAlgorithm)
                .compact();
        cache.put(this.apiKey, token);
        return token;
    
<no_super_class>