package com.dxhy.auth.interceptor;

import javax.annotation.Resource;

import com.dxhy.auth.config.AuthConfig;
import com.dxhy.auth.service.AuthClientService;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;

/**
 * @author jiaohongyang
 * @date 2019年3月26日 下午5:54:56
 *
 */
@Slf4j
public class ClientTokenInterceptor implements RequestInterceptor {
    @Resource
    private AuthClientService authClientService;

    @Override
    public void apply(RequestTemplate requestTemplate) {
        try {
            requestTemplate.header(AuthConfig.clientTokenHeader,
                authClientService.apply(AuthConfig.clientId, AuthConfig.clientSecret));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
