Learn how to implement social login using Google for an existing Spring Boot application using Spring Boot OAuth2 client library. And after successful OAuth2 authentication: Register new user if the user's info does not exist in the database, else update existing user's info.
Here are the steps to code social login with Google:
- Create Google OAuth Credentials
- Configure Spring Security OAuth2 Client
- Update database table & Entity class (add info about authentication provider)
- Update login page
- Code Custom OAuth User & OAuth User Service classes
- Configure Spring Security for OAuth2 authentication
- Implement Authentication Success Handler
- Update CustomerServices: register new / update existing user
Key technologies:
- Spring Boot Web
- Spring Data JPA
- Spring Security
- Spring OAuth2 Client
- Thymeleaf
- Bootstrap & jQuery
- MySQL database
Software programs:
- Java Development Kit (JDK)
- Spring Tool Suite IDE (STS)
- MySQL server & MySQL Workbench
For the companion tutorial, visit: https://www.codejava.net/frameworks/spring-boot/oauth2-login-with-google-example
@CodeJavaمنذ 3 سنواتDownload the sample project in this tutorial: 3
@
@yadav117udayمنذ 2 سنواتthis is the most accurate tutorial which did things properly 1
@
@dmitry1445منذ 3 سنواتThanks for the tutorial. Hi from Belarus) 1
@
@janska029منذ 4 سنواتhi , i need help, my error is oauth2.core.oidc.user.DefaultOidcUser cannot be cast to com.co.rastros.oauth.CustomOAuth2User, i follow the video but in id="hidden3" class="buttons"> the step CustomOAuth2User oAuth2User = (CustomOAuth2User) authentication.getPrincipal() in the class OAuth2LoginSuccessHandler it's not possible, Help. ....وسعت1
@
@ai6566منذ 3 سنواتThank You. This was very informative session.
@
@eugenefeng511العام الماضيThank you for saving me. That's exact what I want.
@
@hanumantdمنذ 3 سنواتCan you please post database table creation scripts? 1
@
@igorpavlenkov3658منذ 3 سنواتThanks for this tutorial. Hello from Russia)
@
@maral-erdenetumursuh4844منذ 3 سنواتHello, thank you for great tutorial. I've question about security implementation in micro service project. In cloud gateway can not add spring-boot-starter-web id="hidden4" class="buttons"> dependency. So cannot extend WebSecurityConfigurerAdapter. How i do my filter this kind of architechture. ....وسعت
@
@xtrange2152قبل 7 أشهرAnh ơi cái login google em ok r nhưng có vấn đề là nếu em edit user theo kiểu gọi MyUserDetail ra để lấy người dùng đang đăng nhập hiện tại thì nó sẽ ra null nếu em login bằng pass vs mk bth thì ok ko sao hết vấn đề ở chỗ đó thôi ạ. Thì phần anh làm là a để oauth2detail riêng ra nên em nghĩ là 2 thg nó ko phân biệt đc nhau ạ em để user role là admin mà login bằng nó ko hiện phần của admin luôn khá ảo ....وسعت
@
@ethandsa1966منذ 4 سنواتThank you for the tutorial. How do I deny access if the user doesn't already exist instead of creating a new user?
@
@stevechao4012منذ 3 سنواتThanks for the great tutorial! I was able to log in using g-mail with my original project!! And I am able to put g-mail user data in SQL Server id="hidden6" class="buttons"> DB. But after I log in with Google, the registered account seem do not recognized with my original roles set thus I get a 403 forbidden when I'm using google accounts to login. Can you suggest any leads to combine my original roles set with google accounts?? Thanks a lot! ....وسعت
@
@user-qe2so5vz4tقبل 10 أشهرanh ơi, tại sao trong fle pom ở cái source code bên dưới phần miêu tả a đính kèm, trong file pom a có để như này <properties> <java.version>1.8</java.version> </properties> e đang dùng java 17 thì e thay 17 vào thì có lỗi bắn ra còn để nguyên thì chạy được lí do là gì anh nhỉ? mong được anh reply ạ ....وسعت
@
@trinhquycong.2001منذ 2 سنواتThis tutorial's great sir, but how can i implement this into a fullstack application, let say Spring boot & Angular, since it involves Rest api, can you give me some advice? Thank you in advance!
@
@HaiNguyen-qm3ftقبل 11 أشهرTrong trường hợp, login with GG thì password trong db là null. Vậy chức năng change password dành cho tài khoản làm cách nào để có thể sử dụng vậy anh. em cảm ơn anh
@
@charagergi5316منذ 3 سنواتI have a question, OAuth2 works with a token for authorization, here I can't see any function for the token. It is managed automatically or we dont use tokens?
@
@tuananhtran4390منذ 2 سنواتAnh có thể làm 1 video với Okta mà SSO đc ko ạ :((
@
@roan1435منذ 2 سنواتHi Nam. I followed almost similar to you what you did in this tutorial. But I'm get and error "principalName cannot be empty". Do you have any idea why i'm getting this error?
@
@phamluc2661منذ 3 سنواتI'm newbie with Spring Boot, having a question Can I use the OAuth2 authentications for mobile app?
@
@David-wf3ccالعام الماضيWhere can we get code for front end and other files not included in git 1
@
@buiucnhan5623منذ 2 سنواتCan you make a video with Reactjs as the front end?
@
@ipox0090منذ 2 سنواتCan you tell me where the OAuth2User you wrote is, why can't I see it. Can you help me explain.
@
@rajashekar5755منذ 4 سنواتNAM im doing project can you please help me with this, When User enters into my website User should register first and then he needs to be verified by Email so that he can login using those crediantials.
@
@tuannguyen-il5ohمنذ 2 سنواتCould you guild to how to force user choose account google to login(when click login with google redirect a page allow choose account google) at video browser get account google we have logined
@
@user-qe2so5vz4tقبل 10 أشهرa ơi lúc em download source code vè chạy thì nó cứ báo lỗi là Connection refused: no further information em kiểm tra lại thông tin trong file properties kĩ lắm rồi mà cứ báo v
@
@shawaalsaif2144منذ 3 سنواتI have two Authentication provider Google and Facebook. As you set authentication provider to google what if the user logs in with facebook?
@
@charagergi5316منذ 3 سنواتHi the video was really helpful, but can I find the source code somewhere? Thank you
@
@VIVEKSINGH-zk4pvمنذ 4 سنواتHey I am getting error principalities cannot be empty
@
@arwaalblooshi6944منذ 4 سنواتCan you please do Linkedin login? thanks
@
@babisvasilopoulos5666منذ 3 سنواتIs any available repository to download the source code
@
@sanghub1642منذ 4 سنواتPlease helps me. I have problem in class Oauth2LoginSuccessHandler with error: can't convert CustomOauth2User to .
@
@vuvankhiem478منذ 3 سنواتAnh cho em hỏi là làm sao để lấy được avatar về được ạ
@
@rahilbaig3873منذ 4 سنواتHi, I am getting an error saying " org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser cannot be cast to com.bookstore.oauth.CustomOAuth2User" id="hidden16" class="buttons"> it is occuring on this line ---> "CustomOAuth2User oAuth2User= (CustomOAuth2User) authentication.getPrincipal();" it cannot able to cast to CustomOAuth2User. ....وسعت2
@
@masnaswamy4067منذ 4 سنواتjava.lang.IllegalArgumentException: principalName cannot be empty., HOW TO SOLVE THIS EXCEPTION BRO
@
@cuongnguyenminh6235منذ 3 سنواتAnh có chanel bằng tiếng Việt ko ạ, em cảm ơn anh
@
@lokeshdandasena6766منذ 3 سنواتit was nice that u have provided some information but it seems like u are starting from the middle as you have files in the application before even starting id="hidden17" class="buttons"> to explain, you are not saying anything about the application (i think you have other microservices as well), you should walk through the application so that the purpose should be clear. For example - you have said to add a property to the entity table, I think you are not clearly describing it. please describe it properly so that it will help others. ....وسعت
@
@sagarsri4143منذ 4 سنواتPlease make video on role based login from scratch
@
@adamdecarte4847منذ 2 سنواتHI, my oAuth2User does not have .getAtribute() method. Only .getAtributes() & .getName()
@
@bennteast1776منذ 2 سنواتCan we please have the full source code, the article doesn't have all the code needed @CodeJava 1
@
@nienpingchen4967منذ 2 سنواتHow can i get the profile photo from facebook or google?(oauth2User.getAttribute("name")? can i get a photo from keyword "name"??) id="hidden18" class="buttons"> Thank you so much for all your springboot tutorial, it help me finish my project , so i can start to find a job ! ....وسعت
مقاطع الفيديو ذات الصلة على Spring Boot OAuth2 Social Login with Google Example:
And I am able to put g-mail user data in SQL Server id="hidden6" class="buttons"> DB. But after I log in with Google, the registered account seem do not recognized with my original roles set thus I get a 403 forbidden when I'm using google accounts to login. Can you suggest any leads to combine my original roles set with google accounts?? Thanks a lot! ....وسعت
<properties>
<java.version>1.8</java.version>
</properties>
e đang dùng java 17 thì e thay 17 vào thì có lỗi bắn ra còn để nguyên thì chạy được
lí do là gì anh nhỉ? mong được anh reply ạ ....وسعت
When User enters into my website User should register first and then he needs to be verified by Email so that he can login using those crediantials.
Connection refused: no further information
em kiểm tra lại thông tin trong file properties kĩ lắm rồi mà cứ báo v
Thank you so much for all your springboot tutorial, it help me finish my project , so i can start to find a job ! ....وسعت