Auth2 scope 权限控制

@PreAuthorize("#oauth2.hasAnyScope('web', 'client')")
@PreAuthorize("#oauth2.hasScope('app')")
@PreAuthorize("#oauth2.hasScope('admin:user')")
@Api(tags = "后台用户的接口")
@RestController
@RequestMapping("sys/user")
@PreAuthorize("#oauth2.hasAnyScope('web', 'client')")
public class SysUserController {
/**
 * 配置第三方应用
 * password 只要是登录都用这个授权方式
 * 客户端授权 用于微服务之间自发的进行远程调用时 资源服务器必须要token的情况 当然也是可以放行服务提供者的接口的
 *
 * @param clients
 * @throws Exception
 */
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
    clients.inMemory()
            .withClient("web")
            .secret(passwordEncoder.encode("web-secret"))
            .scopes("web")
            .authorizedGrantTypes("password")
            .accessTokenValiditySeconds(7200)
            .redirectUris("https://www.baidu.com")
            .and()
            .withClient("client")
            .secret(passwordEncoder.encode("client-secret"))
            .scopes("client")
            .authorizedGrantTypes("client_credentials")
            .accessTokenValiditySeconds(Integer.MAX_VALUE) // 客户端授权 内部调用的永久token 66年
            .redirectUris("https://www.baidu.com")
            // like12 add,20230806,新增手机端支持
            .and()
            .withClient("app")
            .secret(passwordEncoder.encode("app-secret"))
            .scopes("app")
            .authorizedGrantTypes("password")
            .accessTokenValiditySeconds(2592000) // 30天
            .redirectUris("https://www.baidu.com")
    ;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值