yangys
2024-03-29 4b479381a65bd3ef526cb92631d3550f2aa17459
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.qianwen.smartman.modules.auth.endpoint;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import me.zhyd.oauth.model.AuthCallback;
import me.zhyd.oauth.model.AuthToken;
import me.zhyd.oauth.request.AuthRequest;
import me.zhyd.oauth.utils.AuthStateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.qianwen.smartman.common.constant.FmsConstant;
import com.qianwen.core.social.utils.SocialUtil;
import com.qianwen.core.tenant.annotation.NonDS;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
@RequestMapping({"blade-auth"})
@Api(value = "第三方登陆", tags = {"第三方登陆端点"})
@RestController
@NonDS
@ConditionalOnProperty(value = {"social.enabled"}, havingValue = FmsConstant.AUTOMATIC)
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/auth/endpoint/BladeSocialEndpoint.class */
public class BladeSocialEndpoint {
    private static final Logger log = LoggerFactory.getLogger(BladeSocialEndpoint.class);
 
    @GetMapping({"/oauth/render/{source}"})
    @ApiOperation("授权完毕跳转")
    public void renderAuth(@PathVariable("source") String source, HttpServletResponse response) throws IOException {
        AuthRequest authRequest = SocialUtil.getAuthRequest(source);
        String authorizeUrl = authRequest.authorize(AuthStateUtils.createState());
        response.sendRedirect(authorizeUrl);
    }
 
    @RequestMapping({"/oauth/callback/{source}"})
    @ApiOperation("获取认证信息")
    public Object login(@PathVariable("source") String source, AuthCallback callback) {
        AuthRequest authRequest = SocialUtil.getAuthRequest(source);
        return authRequest.login(callback);
    }
 
    @RequestMapping({"/oauth/revoke/{source}/{token}"})
    @ApiOperation("撤销授权")
    public Object revokeAuth(@PathVariable("source") String source, @PathVariable("token") String token) {
        AuthRequest authRequest = SocialUtil.getAuthRequest(source);
        return authRequest.revoke(AuthToken.builder().accessToken(token).build());
    }
 
    @RequestMapping({"/oauth/refresh/{source}"})
    @ApiOperation("续期令牌")
    public Object refreshAuth(@PathVariable("source") String source, String token) {
        AuthRequest authRequest = SocialUtil.getAuthRequest(source);
        return authRequest.refresh(AuthToken.builder().refreshToken(token).build());
    }
}