首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >springboot+swagger3+oauth2 client credentials模式授权

springboot+swagger3+oauth2 client credentials模式授权

作者头像
路过君
发布2021-12-07 16:03:31
发布2021-12-07 16:03:31
1.1K0
举报

效果

文档页面上出现授权按钮

点击授权按钮输入客户端id,密码获取令牌

测试请求中自动携带令牌

版本

springboot 2.5.4 springdoc 1.5.10

依赖

代码语言:javascript
复制
<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-webmvc-core</artifactId>
    <version>1.5.10</version>
</dependency>
<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-security</artifactId>
    <version>1.5.10</version>
</dependency>

配置

代码语言:javascript
复制
@Bean
public OpenAPI api() {
    return new OpenAPI()
            .info(new Info().title("My API")
                    .description("My sample application")
                    .version("v0.0.1")
                    .license(new License().name("Apache 2.0").url("https://blog.csdn.net/zhoudingding")))
            .externalDocs(new ExternalDocumentation()
                    .description("My Blog")
                    .url("https://blog.csdn.net/zhoudingding"))
            // 注册SecuritySchemes
            .components(new Components().securitySchemes(Map.of(
                    "Client Credentials",
                    new SecurityScheme().type(SecurityScheme.Type.OAUTH2)
                            .flows(new OAuthFlows().clientCredentials(
                                    new OAuthFlow().tokenUrl(oauth2Host + "/oauth/token")
                                            .scopes(new Scopes().addString("all", "Grants for all."))
                            ))
            )))
            .addSecurityItem(
                    new SecurityRequirement().addList("Client Credentials")
            );
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021/09/18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 效果
  • 版本
  • 依赖
  • 配置
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档