package org.jeecg.modules.oauth2_server.controller;

//import cn.dev33.satoken.oauth2.logic.SaOAuth2Template;

import cn.dev33.satoken.oauth2.model.SaClientModel;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.modules.oauth2_server.util.SaOAuth2Templates;
import org.jeecg.modules.system.entity.SysTenant;
import org.jeecg.modules.system.service.ISysTenantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * Sa-Token OAuth2.0 整合实现 
 * @author kong
 */
@Component
public class SaOAuth2TemplateImpls extends SaOAuth2Templates {

	@Autowired
	private ISysTenantService sysTenantService;
	@Override
	public SaClientModel getClientModel(String clientId) {
		SysTenant client = sysTenantService.getOne(new QueryWrapper<SysTenant>().eq("client_id", clientId).last("limit 1"));
		if(client!=null) {
			return new SaClientModel()
					.setClientId(client.getClientId())
					.setClientSecret(client.getClientSecret())
					.setAllowUrl("*")
					.setContractScope("userinfo");
		}
		return null;
	}
	@Override
	public String getOpenid(String clientId, Object loginId) {
		return clientId+loginId;
	}
}
