OAuth2 Authentication with Spring Security and Github | Spring Boot Backend #3.3

Ғылым және технология

In this video I will show how to authenticate using the OAuth2 system with Spring Security and Github. For that, I will need to create a Github login application and connect it to my Spring Boot application with Spring Security to allow it to perform the necessary requests.
This is the third part of the third video of a playlist where I show how to create a Spring Boot Backend how to create a website: • Spring Boot
Content of the video:
* How works the OAuth2 authentication and which components it has;
* Which types of OAuth2 authentication it exist;
* Creation of a Github application to use the OAuth2 authentication;
* Configuration of Spring Security to authenticate over Github using OAuth2;
* Sequence of requests of the OAuth2 authentication;
* Usage of the @AuthenticationPrincipal annotation to fetch the user account from Github.
Repository: github.com/serlesen/backend-s...
My NEW eBook: sergiolema.dev/git-book/
Blog: bit.ly/47ornJL
LinkedIn: bit.ly/41Nn61q
Facebook: bit.ly/47rc9nh
My Desktop:
• Laptop: Macbook Pro 16' 2019
• Gaming Chair: amzn.to/47Vu6ed
• Mouse: amzn.to/3HoBwM1
• Desk: amzn.to/48Tc5Oi
• Screen: amzn.to/48VZkCL
Icons:
* Server by priyanka from the Noun Project
* web browser by Fernanddo Santtander from the Noun Project
* web browsing by H Alberto Gongora from the Noun Project
* account by fajar hasyim from the Noun Project
* Lock by Aya Sofya from the Noun Project
* id by Adrien Coquet from the Noun Project

Пікірлер: 18

  • @repository2883
    @repository2883 Жыл бұрын

    Muuy bueno este video me está aclarando varias dudas! Hace mucho dije que seguro tus video me iban a servir para más adelante porque tocas temas muy buenos, dificiles y que no se encuentra tanto en español, efectivamente aca estoy! Graciaas!

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    Жыл бұрын

    Muuuchas gracias por tu confianza. Intento ser diferente a los demás y realizar videos sobre temáticas ya profesionales (y no sobre problemas de escuela).

  • @CuongTran-vn5mt
    @CuongTran-vn5mt3 жыл бұрын

    Thank you. Your videos helped me a lot.

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    3 жыл бұрын

    Thanks to you to follow me!

  • @ducnguyentuan8778
    @ducnguyentuan87783 жыл бұрын

    smooth DIE. what are you using ?

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    3 жыл бұрын

    I'm using Intellij

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    3 жыл бұрын

    If you want some tips, check this video, kzread.info/dash/bejne/pXqM1qyPhJyecbg.html

  • @alxx736
    @alxx7362 жыл бұрын

    Consulta,estaba queriendo authenticar con multiples providers (Facebook,Twitter,etc) . Mi confusion viene porque se que existia Spring Social como proyecto . Puede ser que no se use mucho ya? Por lo que veo ,en muchos lugares ,se hace como vos estas explicando . Quisiera saber si Spring Social murio ,y si cuando puedas ,hacer algun video con multiples opciones de Login . Mas que nada ,para ver las mejores practicas .Saludos!!

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    2 жыл бұрын

    Efectivamente, Spring Social no se utiliza ya. El proyecto se ha dejado de mantener en Julio 2019, spring.io/projects/spring-social#overview. Para utilizar varias plataformas de login, puedes crear endpoints dedicados a cada plataforma, o el mismo endpoint que es capaz de recibir llamadas de multiples plataformas (en este caso, tiene que ser capaz de responder a la plataforma adecuada según donde empieces el login). Personalmente, cuando he hecho logins desde varias plataformas, tenía varios endpoints, uno por plataforma de login (Github, Facebook, GMail...).

  • @alxx736

    @alxx736

    2 жыл бұрын

    @@TheDevWorldbySergioLema p Perfecto querido ! Mil gracias ,entonces la manera de hacerlo ahora esta . Gracias nuevamente por tu tiempo !

  • @Guitar_Dev
    @Guitar_Dev2 ай бұрын

    Hi Congratulations for you tutorial The github pop is showing error 404.

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    2 ай бұрын

    Thanks. I've just tried it again now, and the links work well: github.com/serlesen/backend-social-network/tree/chapter_3_3

  • @Guitar_Dev

    @Guitar_Dev

    2 ай бұрын

    @@TheDevWorldbySergioLema Thanks for the reply. I tried demo is working fine. But in my project I use spring boot 3.1.2 and java 17.

  • @Guitar_Dev

    @Guitar_Dev

    2 ай бұрын

    I found the issue was my github account !! Thanks your project helped me figure out the issue

  • @bohdankalika
    @bohdankalika Жыл бұрын

    I've tried to add this implementation info JWT + Cookies based auth implementation (previous 2 tutorial). And my code looks like this: public class SecurityConfig { ... @Bean protected SecurityFilterChain filetChain(HttpSecurity http) throws Exception { http .exceptionHandling().authenticationEntryPoint(userAuthenticationEntryPoint) .and() .addFilterBefore(new UsernamePasswordAuthFilter(userAuthenticationProvider), BasicAuthenticationFilter.class) .addFilterBefore(new CookieAuthenticationFilter(), UsernamePasswordAuthFilter.class) .addFilterBefore(new JwtAuthFilter(userAuthenticationProvider), UsernamePasswordAuthFilter.class) .csrf().disable() .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS) .and() .authorizeHttpRequests(authorize -> authorize .requestMatchers(HttpMethod.POST, "/v1/signIn", "/v1/signUp").permitAll() .anyRequest().permitAll()) // .oauth2Login(); //

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    Жыл бұрын

    Your application returns a 500 error code, you should also have a stacktrace with more information.

  • @bohdankalika

    @bohdankalika

    Жыл бұрын

    @@TheDevWorldbySergioLema is it enough? java.lang.NullPointerException: Cannot invoke "org.springframework.security.oauth2.core.user.OAuth2User.getAttribute(String)" because "principal" is null at com.bkalika.socialnetwork.services.AuthenticationService.findOrCreateByLogin(AuthenticationService.java:85) ~[classes/:na] at com.bkalika.socialnetwork.controllers.CommunityController.getCommunityMessages(CommunityController.java:38) ~[classes/:an] ....... not important part or error at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.0.0.jar:6.0.0] at com.bkalika.socialnetwork.config.UsernamePasswordAuthFilter.doFilterInternal(UsernamePasswordAuthFilter.java:45) ~[classes/:na] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.0.2.jar:6.0.2] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.0.0.jar:6.0.0] at com.bkalika.socialnetwork.config.JwtAuthFilter.doFilterInternal(JwtAuthFilter.java:46) ~[classes/:na] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:116) ~[spring-web-6.0.2.jar:6.0.2] at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:374) ~[spring-security-web-6.0.0.jar:6.0.0] at com.bkalika.socialnetwork.config.CookieAuthenticationFilter.doFilterInternal(CookieAuthenticationFilter.java:37) ~[classes/:na]

  • @TheDevWorldbySergioLema

    @TheDevWorldbySergioLema

    Жыл бұрын

    Ok, I think i figured out the problem. You have the Principal object null from the controller. This is because it's not filled in your filters. I'v"e checked, and the JWT filter fills the Principal object correctly, nevertheless the Cookie filter doesn't. The Cookie filter only reads the token but not the User object. You must send the User object to Principal as done in the JWT filter. Hope it help you (www.buymeacoffee.com/serlesen)

Келесі