一 进行授权页
浏览器输入 http://localhost:8081/oauth/authorize?response_type=code&r来1源gaodai#ma#com搞*代#码1网edirect_uri=http://localhost:8081/callback&client_id=android1&scop=all
二 使用资源站用户登陆
自动跨到资源登陆页,先登陆
三 授权资源类型
登陆成功后,去授权你的资源,这些资源是在AuthorizationServerConfig.configure
方法里配置的
@Override public void configure(ClientDetailsServiceConfigurer clients) throws Exception { clients.inMemory() .withClient(ClientID) .secret(passwordEncoder.encode(ClientSecret)) .authorizedGrantTypes("authorization_code", "refresh_token", "password", "implicit") .scopes("read","write","del","userinfo") .redirectUris(RedirectURLs); }
五 获取access_token
我们拿着code就要再去授权服务器去获取token了,你可以在你的代码里写这个,也可以手动拿着code,去拼成一个url,再去拿token,就像这下面的实例。
注意向oauth/token发的是post请求,client_id和client_secret如果在url上传递,如果在AuthorizationServerConfig
类的configure方法中开启allowFormAuthenticationForClients
,代码如下
@Override public void configure(AuthorizationServerSecurityConfigurer oauthServer) throws Exception { oauthServer.tokenKeyAccess("permitAll()") .checkTokenAccess("isAuthenticated()") .allowFormAuthenticationForClients();//支持把secret和clientid写在url上,否则需要在头上 }