Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

授权码模式,我获取了token了,但是似乎token无效?每次都需要登录,试了很多方法,请问这个token怎样使用才生效呢? #17

Open
shancg opened this issue Jul 9, 2018 · 14 comments

Comments

@shancg
Copy link

shancg commented Jul 9, 2018

No description provided.

@shancg
Copy link
Author

shancg commented Jul 9, 2018

用这个获取token,要登录一次的

@shancg
Copy link
Author

shancg commented Jul 9, 2018

http://localhost:8080/qq/info/250577914/access_token=be1f0257-927f-473d-ab59-6d2dd6a02185
用这个访问的,postman,get、post都试了,不好用,还是让登陆

@shancg
Copy link
Author

shancg commented Jul 9, 2018

http://localhost:8080/qq/info/250577914?access_token=be1f0257-927f-473d-ab59-6d2dd6a02185
应该是这样,反正token带在后面,放在头里也试了

@shancg
Copy link
Author

shancg commented Jul 9, 2018

当然获取token后,直接在当前浏览器开新的页面是可以的,但这应该是登录后有session了

@cailili19931106
Copy link

会需要登录是因为资源服务器和授权服务器在一个应用里的话,可能会被主过滤器拦截,你把主过滤器拦截的url给限制一下,就是springsecurity http.requestMatchers().antMatchers("/", "/home","/login","/oauth/authorize").and()
.authorizeRequests()
.antMatchers("/", "/home","/login","/oauth/authorize").permitAll()
.and() 就是通过requestMatchers()去限制一下

@cailili19931106
Copy link

你之前的获取token之后直接在浏览器打开,你可以试试看,改了token的应该也是可以访问资源的,如果你的是改了token也获取到资源了的话,那就说明你的请求进的应该是进了主过滤链了。那就可以通过requestMatchers()去限制一下。

@shancg
Copy link
Author

shancg commented Jul 11, 2018

@cailili19931106 我试过这样限制,也是不好用,要么就是不需要认证,要么就还是需要登录,你有试过,又好用的配置?是不是我把这两个应用分开就会好用?

@cailili19931106
Copy link

我试过这样的,我是在 WebSecurityConfigurer 的 HttpSecurity 用requestMatchers() 去限制了,,同样在ResourceServerConfig 资源服务器的http 里也去限制了,在ResourceServerConfig public void configure(HttpSecurity http) throws Exception {
// @Formatter:off
http.requestMatchers().antMatchers("/qq/**").and()
.authorizeRequests().anyRequest().authenticated();
// @Formatter:on
}这样,不管客户端,只要带着acssess_token过来了,就可以访问资源了,不用登录,token不对,会返回invalid token 的错误信息 @shancg

@shancg
Copy link
Author

shancg commented Jul 11, 2018

@cailili19931106 我下班了试试,谢谢

@cailili19931106
Copy link

不客气,我也最近刚好用这个。可以debug 试试看,看就是带着aceess_token的请求,最终是进入了哪条过滤链。

@lexburner
Copy link
Owner

@shancg @cailili19931106 授权码模式demo已更新,pull 之后重新看下吧

@xnxuehai
Copy link

@lexburner 认证和资源分开开发 如何使跳过登录直接获取code呢?

@telami
Copy link

telami commented Sep 24, 2019

@xnxuehai 不管是不是分开,都是需要登录的,不然要授权谁的信息呢。

我之前跟你有同样的疑问,然后的debug了一圈,spring要从session里取出以这个为key【SPRING_SECURITY_CONTEXT_KEY】的认证信息,通过认证了才会往后面的过滤器链走

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants