88import life .majiang .community .dto .GithubUser ;
99import life .majiang .community .provider .GithubProvider ;
1010import org .springframework .beans .factory .annotation .Autowired ;
11+ import org .springframework .beans .factory .annotation .Value ;
1112import org .springframework .stereotype .Controller ;
1213import org .springframework .web .bind .annotation .GetMapping ;
1314import 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 );
0 commit comments