您当前的位置: 首页 >  I.T10001 spring

springcloud搭建Oauth2.0开放平台-效果(2)

I.T10001 发布时间:2020-01-11 19:20:03 ,浏览量:3

在Spring Cloud需要使用oauth2来实现多个微服务的统一认证授权,通过向OAUTH服务发送某个类型的grant type进行集中认证和授权,从而获得access_token,而这个token是受其他微服务信任的,我们在后续的访问可以通过access_token来进行,从而实现了微服务的统一认证授权。

客户端根据约定的ClientID、ClientSecret、Scope来从Access Token URL地址获取AccessToken,并经过AuthURL认证,用得到的AccessToken来访问其他资源接口。

 Spring Cloud oauth2 需要依赖Spring security

1、获取授权码,回调返回code(code有效期10分钟,使用过后必须重新获取),如下图:

http://localhost:8115/oauth/authorize?response_type=code&client_id=client_1&redirect_uri=http://www.baidu.com

2、授权码模式:通过code,获取accessToken,如下图:

http://localhost:8115/oauth/token?grant_type=authorization_code&code=wOWRd9&redirect_uri=http://www.baidu.com&scope=all&client_id=client_1&client_secret=123456

3、密码模式:通过用户名和密码,获取accessToken,如下图:

 http://localhost:8115/oauth/token?grant_type=password&redirect_uri=http://www.mayikt.com&scope=all&username=user_1&password=123456&client_id=client_1&client_secret=123456

4、刷新token

http://localhost:8115/oauth/token?grant_type=refresh_token&refresh_token=02521fd5-5233-4c80-b12a-231bef1c1a14&client_id=client_1&client_secret=123456

5、检查token有效期:

http://localhost:8115/oauth/check_token?token=2eee1e81-d14c-4d24-91f6-42d4d3c4a348

6、客户端访问

关注
打赏
1688896170
查看更多评论

I.T10001

暂无认证

  • 3浏览

    0关注

    154博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.4649s