Skip to content

Commit beac1fd

Browse files
committed
增加配置文->> ithub.clientã
1 parent 8314b94 commit beac1fd

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

.tgitconfig

Whitespace-only changes.

src/main/java/life/majiang/community/controller/AuthorizeController.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import life.majiang.community.dto.GithubUser;
99
import life.majiang.community.provider.GithubProvider;
1010
import org.springframework.beans.factory.annotation.Autowired;
11+
import org.springframework.beans.factory.annotation.Value;
1112
import org.springframework.stereotype.Controller;
1213
import org.springframework.web.bind.annotation.GetMapping;
1314
import org.springframework.web.bind.annotation.RequestParam;
@@ -18,15 +19,23 @@ public class AuthorizeController {
1819
@Autowired // 把spring容器的实例加载到当前上下文
1920
private GithubProvider githubProvider;
2021

21-
@GetMapping("/callback") // 登录成功后返回到登录页
22+
// 加载配置文件--github.client
23+
@Value("${github.client.id}")
24+
private String clientID;
25+
@Value("${github.client.secret}")
26+
private String clientSecret;
27+
@Value("${github.client.uri}")
28+
private String clientUri;
29+
30+
@GetMapping("/callback") // 登录成功后返回到登录页
2231
// 接收返回后的参数 code, state
2332
public String callback(@RequestParam(name = "code") String code,
2433
@RequestParam(name = "state") String state) {
2534
AccessTokenDTO accessTokenDTO = new AccessTokenDTO();
26-
accessTokenDTO.setClient_id("639f4c8d6441c6136b44");
27-
accessTokenDTO.setClient_secret("024fb99f36d3ce6764d6e00eb15c9545aa284cb9");
35+
accessTokenDTO.setClient_id(clientID);
36+
accessTokenDTO.setClient_secret(clientSecret);
2837
accessTokenDTO.setCode(code);
29-
accessTokenDTO.setRedirect_uri("http://localhost:8080/callback");
38+
accessTokenDTO.setRedirect_uri(clientUri);
3039
accessTokenDTO.setState(state);
3140
githubProvider.getAccess_token(accessTokenDTO);
3241
String accessToken = githubProvider.getAccess_token(accessTokenDTO);
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
# 更改server端口
2-
server.port=8080
2+
server.port=8080
3+
4+
# Git第三方授权应用配置 回调地址
5+
github.client.id= 639f4c8d6441c6136b44
6+
github.client.secret=024fb99f36d3ce6764d6e00eb15c9545aa284cb9
7+
github.client.uri=http://localhost:8080/callback

0 commit comments

Comments
 (0)