Tech article

Implement GitHub OAuth2 Authorization Login in Springboot

Community description: GitHub 登录本质上是 OAuth2 授权码模式 把用户重定向到 GitHub 授权页面 GitHub 授权后会跳转回你的回调接口,带上一个 code,你拿这个 code 换...

Dev.to | Sep 13, 2026 | YYT-0901

Automated excerpt

0. 先去 GitHub 申请 OAuth App GitHub → Settings → Developer settings → OAuth Apps → New OAuth App,拿到 Client ID、Client Secret,并配置 Authorization callback URL(比如 http://your-domain. com/api/auth/callback/github)。 redisService. set("oauth:github:state:" + state, "1", 5, TimeUnit. MINUTES); if (state == null || ! redisService. hasKey("oauth:github:state:" + state)) { redisService. set("oauth:token:code" + tokenCode, loginVo, 30, TimeUnit. SECONDS); String redirectUrl = githubOAuthProperties. getFrontendCallbackUrl() + "? code=" + tokenCode; LoginVo loginVo = (LoginVo) redisService. get("oauth:token:code" + code); redisService参考:https://dev. to/yyt0901/common-dependency-configuration-for-spring-boot-354-java-1721-1li7 (CTRL + F to search redisService in website) if (sysUser == null || sysUser. getStatus() == 0) { sysUser. setNickname(githubUser. getName() ! = null ? githubUser.

Selected automatically from source text; not independently written or fact-checked. Read the original for full context.

Read the original article

More tech news