oauth2 学习
准备工作 :
如果是通过数据库进行授权,需在oauth2 的客户端配置表(oauth_client_details)中配置相关信息 :
设置信息如下 :
客户端编号(client_id) 为 client;
资源编号(resource_ids) 为 * (全部资源);
客户端的访问密匙(Client Secret ) 为 123456 (该值需要加密存储);
客户端申请的权限范围(scope) 为 read(可设置为 read|只读、write|只写、trust);
客户端支持的授权类型(authorized_grant_types)为
client_credentials|客户端凭证,implicit|隐藏式,authorization_code|授权码,refresh_token|可刷新,password密码式;
客户端访问的资源地址(web_server_redirect_uri)为 http://127.0.0.1;
指定spring security的用户(authorities)为 * 所有用户都能访问.
如果是直接在内存中存储,需在oauth2 的配置项中直接设置,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| @Override public void configure(ClientDetailsServiceConfigurer clients) throws Exception { String finalSecret = "{bcrypt}"+new BCryptPasswordEncoder().encode("123456"); clients.inMemory().withClient("client") .resourceIds("*") .authorizedGrantTypes("client_credentials","implicit", "authorization_code", "refresh_token","password") .scopes("read") .redirectUris("http://127.0.0.1") .authorities("*") .secret(finalSecret); }
|