springboot2.0整合oauth2.0

总结之前看了很多网上大神的实例,例子也是引用大神的,谢谢了!!!

1、在做springboot2.0和oauth2.0整合的时候(密码模式),有个问题一直想不通,请求的url中有用户名密码:(http://localhost:8080/oauth/token?grant_type=password&client_id=client_2&client_secret=123456&username=user_1&password=123456)

而代码中没有密码,他怎么知道这个用户是否是正确操作的呢?,下图用户名和密码都是写死的,看不出来用户名密码是如何传递的,这个类 UserDetailsService   有方法 loadUserByUsername,如果是密码模式的时候,只有一个参数,打印出来发现是输入的用户名,那么密码呢?只通过用户名就能判断是正确的用户?

2、由于请求token的时候,我们调用的是:http://xxx/oauth/token?grant_type=password&client_id=client_2&client_secret=123456&username=user_1&password=123456,

oauth/token  : 该方法不是我们自己写的,就看看该方法怎么接收密码的,为什么UserDetailsService  只有一个username,而没有密码,全局搜索后,在TokenEndpoint 中有oauth/token 方法,跟着源码看后,原来接收到参数后,她已经存放了,而UserDetailsService  中是从存放的对象中查询是否存在,如图:

待续......

发布了23 篇原创文章 · 获赞 3 · 访问量 6858

猜你喜欢

转载自blog.csdn.net/weixin_41834814/article/details/90672537