package com.tofly.auth.config;

import com.netflix.loadbalancer.IRule;
import com.tofly.auth.balance.ToflyChooseBalancerRule;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.RemoteTokenServices;

/**
 * @author Administrator
 * @date 2019/9/9  17:01
 */
@Configuration
@Slf4j
public class AutoAPIConfiguration{

    @Value("${security.oauth2.resource.token-info-uri}")
    private String checkTokenEndpointUrl;

    @Value("${security.oauth2.resource.loadBalanced}")
    private boolean loadBalanced;

    @Value("${security.oauth2.client.client-id}")
    private String clientid;
    @Value("${security.oauth2.client.client-secret}")
    private String clientsecret;

    @Bean
    public RemoteTokenServices remoteTokenServices(){
        RemoteTokenServices remoteTokenServices=new RemoteTokenServices();
        remoteTokenServices.setCheckTokenEndpointUrl(checkTokenEndpointUrl);
        log.info("-----clientid:{},clientsecret:{}",clientid,clientsecret);
        remoteTokenServices.setClientId(clientid);
        remoteTokenServices.setClientSecret(clientsecret);
        return  remoteTokenServices;
    }

//    @Bean
//    public IRule getIRule(){
//        return new ToflyChooseBalancerRule();
//    }

}

