- OAuth 2.0 Cookbook
- Adolfo Eloy Nascimento
- 248字
- 2021-07-08 09:35:05
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.
- JavaScript從入門到精通(微視頻精編版)
- Learn TypeScript 3 by Building Web Applications
- 深入淺出WPF
- 羅克韋爾ControlLogix系統(tǒng)應(yīng)用技術(shù)
- TypeScript圖形渲染實戰(zhàn):基于WebGL的3D架構(gòu)與實現(xiàn)
- YARN Essentials
- 精通Scrapy網(wǎng)絡(luò)爬蟲
- 微信公眾平臺開發(fā):從零基礎(chǔ)到ThinkPHP5高性能框架實踐
- Reactive Programming With Java 9
- Python High Performance Programming
- R數(shù)據(jù)科學(xué)實戰(zhàn):工具詳解與案例分析
- Java Web從入門到精通(第2版)
- 零基礎(chǔ)C#學(xué)習(xí)筆記
- PHP 8從入門到精通(視頻教學(xué)版)
- Java并發(fā)實現(xiàn)原理:JDK源碼剖析