OAuth2 token个人笔记

1.spring security oauth2简易的分为三个步骤

  • 配置资源服务器

  • 配置认证服务器

  • 配置spring security

2.oauth2根据使用场景不同,分成了4种模式

  • 授权码模式(authorization code)

  • 简化模式(implicit)

  • 密码模式(resource owner password credentials)

  • 客户端模式(client credentials)

下面是我调研的密码模式使用方式:

1.基本认证可以通过请求头传递

键值对:Authorization=bearer13b22000-1224-4ac2-b467-bb0f376dfd87

这里不区分大小写,在请求头中携带token验证可以访问需要认证的接口。

 

这里访问check_token接口时,需要把客户端基本认证加上,参数token=41c96126-019c-47bb-887d-7100dc2e7670,即可访问。

http://127.0.0.1:1203/oauth/check_token?token=41c96126-019c-47bb-887d-7100dc2e7670  

2.基本认证也同样可以通过参数传递

http://127.0.0.1:1203/api/member?access_token=41c96126-019c-47bb-887d-7100dc2e7670

没有配置.secret(new BCryptPasswordEncoder().encode("browser") ),并且也没有声明使用加密

http://127.0.0.1:1203/oauth/token?grant_type=password&client_id=browser&username=1&password=1   post请求

如果你使用了密码加密规则,那么客户端密码也需要以同样的规则声明。并且在使用的时候一定要加上客户端密码,不能只使用客户端账号来进行认证。而且需要在相关configure方法中配置.secret(new BCryptPasswordEncoder().encode("browser") ),没有配置不行,因为使用了加密方式OAuth2会进行校验。

@Override
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
       // clients.withClientDetails(clientDetails());
        clients.inMemory()
                .withClient("browser")
                .secret(new BCryptPasswordEncoder().encode("browser") )
                .authorizedGrantTypes("refresh_token", "password")
                .scopes("read","write");
    }

http://127.0.0.1:1203/oauth/token?grant_type=password&username=1&password=1&client_id=browser&client_secret=browser

http://127.0.0.1:1203/oauth/token?grant_type=refresh_token&refresh_token=78fc9d39-c9ea-42d1-a5e7-12f83ac770f6&client_id=browser   post请求

http://127.0.0.1:1203/oauth/token?grant_type=refresh_token&refresh_token=78fc9d39-c9ea-42d1-a5e7-12f83ac770f6&client_id=browser&client_secret=browser   post请求

参数传递 不支持check_token接口,该接口只可以使用请求头传递

 

 


 
 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值