package com.xjrsoft.module.system.controller;

import com.xjrsoft.common.constant.GlobalConstant;
import com.xjrsoft.module.system.service.IOauthService;
import io.swagger.annotations.Api;
import lombok.AllArgsConstructor;
import me.zhyd.oauth.model.AuthCallback;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: tzx
 * @Date: 2023/8/8 8:45
 */
@Api(tags = "第三方登录模块")
@RestController
@RequestMapping(GlobalConstant.OAUTH_MODULE_PREFIX)
@AllArgsConstructor
public class OauthController {

    private final IOauthService oauthService;

    /**
     * oauth平台中配置的授权回调地址，以本项目为例，在创建github授权应用时的回调地址应为：http://127.0.0.1:8443/oauth/callback/github
     */
    @RequestMapping("/callback/{source}")
    public void login(@PathVariable("source") String source, AuthCallback callback, HttpServletRequest request, HttpServletResponse response) throws IOException {
        oauthService.oAuthLogin(source, callback,request,response);
//
//        response.sendRedirect("http://localhost:3100/#/login?token=" + loginVo.getToken());
//        return R.ok();
    }

}
