官术网_书友最值得收藏!

How it works...

An important thing that we did for this recipe was to bind the application users to their respective connection with the OAuth 2.0 Provider (Google in this case). It's important because by doing so, we have a connection per user, unlike the other recipes using Spring Social. But instead of allowing users to register themselves to the social-google1 application, we are using an in-memory model using pre-defined user credentials, as presented in the following code:

auth.inMemoryAuthentication() 
   .withUser("adolfo").password("123").authorities("USER") 
   .and() 
   .withUser("jujuba").password("123").authorities("USER");

So, when running the application and pointing your browser to http://localhost:8080, you must be prompted by an authentication form, as follows.

Enter one of the credentials we declared within the SecurityConfiguration class and click on the Login button, which will lead you to the following page:

This is the page where you might choose to connect with Google by clicking on Connect to Google, which will redirect you to Google's authentication and authorization form as presented in the following screenshot:

Authenticate yourself and grant all the requested permissions and you will be redirected back to the connected page:

Click on the link here and you will be redirected to the profile's HTML view which will retrieve your name from the Google Plus API. Now, if you go to http://localhost:8080/logout, you will be logged out, as you might expect, and if you try to log in with another user you will have to start a new connection flow proving that you have a connection per logged user.

主站蜘蛛池模板: 吴江市| 昆明市| 诸城市| 镇康县| 通许县| 高邑县| 张家界市| 嘉荫县| 邹平县| 山西省| 阿勒泰市| 揭阳市| 同仁县| 临沭县| 四川省| 普安县| 句容市| 中西区| 金秀| 屯留县| 灵丘县| 车致| 苏尼特左旗| 云阳县| 海口市| 剑河县| 罗田县| 隆德县| 介休市| 伊宁市| 华容县| 工布江达县| 武邑县| 祁连县| 乌鲁木齐县| 甘谷县| 萍乡市| 大安市| 哈尔滨市| 余江县| 嘉荫县|