spring oauth2理解
2019-09-22 18:38 Spiderman25 阅读(335) 评论(0) 收藏 举报oauth2服务端负责维护数据与登录、刷新等操作,而客户端只需要指定数据库源或security:oauth2:resource:user-info-uri即可,这时客户端会从数据库(数据库源)获取或oauth的服务端获取(security:oauth2:resource:user-info-uri),如果要有password模式AuthorizationServerConfiguration中一定要设置好UserDetailsService及authenticationManager(详情看深入理解...一书的14章)。客户端登录其实对应的是oauth_client_details,而密码登录对应的是用户。所以不要以为客户端就是用户。
OAuth2心得
服务器:
1授权服务器:负责维护数据与登录、刷新等操作
2资源服务器:需要指定数据库源或security:oauth2:resource:user-info-uri即可,uri由授权服务器提供
角色:
1客户端
2用户
授权方式:
1授权码模式
2简化模式
3密码模式(AuthorizationServerConfiguration中一定要设置好UserDetailsService及authenticationManager)
4客户端模式(AuthorizationServerConfiguration中设置内存的客户端或数据库的客户端)
各种模式都要用户到客户端,所以可设置authorizedGrantTypes的值为client_credentials,implicit,authorization_code,refresh_token,password中的任意个,设置了才有对应的效果
权限
如果是密码模式,获得的权限为用户的权限,如果为客户端,获得的权限为客户端权限
测试
1、code:get
http://localhost:8080/oauth/authorize?response_type=code&client_id=curl_admin&state=xyz&redirect_uri=http%3A%2F%2F127.0.0.1
http://localhost:8080/oauth/token?grant_type=authorization_code&code=pouOXY&redirect_uri=http://127.0.0.1&client_id=curl_admin&client_secret=user
2、refresh:post
http://localhost:8080/oauth/token?grant_type=refresh_token&refresh_token=274842bc-1730-49d1-9526-dd7bacd6270f&client_id=curl_admin&client_secret=user(没成功,进入UserDetailsService,username为curl_admin,报空指针)
3、client:post
http://localhost:8080/oauth/token?grant_type=client_credentials&client_id=curl_admin&client_secret=user
4、password:post
http://localhost:8080/oauth/token?grant_type=password&client_id=curl_admin&client_secret=user&username=oauth_admin&password=user
对应网址https://blog.csdn.net/Victor_An/article/details/81510874(这个例子要参照精入书籍AuthorizationServerConfiguration加入UserDetailsService)
反正看详情看深入理解与https://blog.csdn.net/Victor_An/article/details/81510874
浙公网安备 33010602011771号