Skip to content

Ken-Chy129/openauth-spring-boot-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

OpenAuth Spring Boot Starter

OpenAuth 的 Spring Boot 自动配置封装,通过 application.yml 配置即可快速集成第三方 OAuth2 授权登录。

功能特性

  • 零代码接入application.yml 配置平台参数即可使用
  • 自动装配:Spring Boot 自动配置,注入 ThirdAuthRequestFactory
  • Redis State 缓存:可选的 Redis 缓存,适用于分布式部署
  • 自定义扩展:支持通过配置注册自定义平台

快速开始

1. 添加依赖

<dependency>
    <groupId>cn.ken</groupId>
    <artifactId>thirdauth-spring-boot-starter</artifactId>
    <version>2.0.1-SNAPSHOT</version>
</dependency>

2. 配置平台参数

thirdauth:
  type:
    github:
      client-id: your-client-id
      client-secret: your-client-secret
      redirect-uri: http://localhost:8080/callback/github
    qq:
      client-id: your-app-id
      client-secret: your-app-key
      redirect-uri: http://localhost:8080/callback/qq
  cache:
    type: redis  # 可选,默认使用内存缓存

3. 使用

@RestController
@RequiredArgsConstructor
public class AuthController {

    private final ThirdAuthRequestFactory factory;

    @GetMapping("/login/{platform}")
    public String login(@PathVariable String platform) {
        AuthRequest authRequest = factory.get(platform);
        return "redirect:" + authRequest.authorizeUrl();
    }

    @GetMapping("/callback/{platform}")
    public AuthUserInfo callback(@PathVariable String platform, AuthCallback callback) {
        AuthRequest authRequest = factory.get(platform);
        AuthResponse<AuthToken> tokenResp = authRequest.getAccessToken(callback);
        AuthResponse<AuthUserInfo> userResp = authRequest.getUserInfo(tokenResp.getData());
        return userResp.getData();
    }
}

配置项

配置 说明 默认值
thirdauth.enabled 是否启用 true
thirdauth.type.{platform} 各平台 OAuth2 配置
thirdauth.cache.type State 缓存类型(default / redis default

技术栈

  • Java 17
  • Spring Boot 3.0
  • OpenAuth 核心库
  • Redis(可选)

About

OpenAuth 的 Spring Boot Starter | yml 配置即可接入 GitHub/Gitee/QQ 等第三方 OAuth2 登录,支持 Redis State 缓存

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages