Upgrade to Pro — share decks privately, control downloads, hide ads and more …

OAuth2 & OpenID Connect with Spring Security

Avatar for UwaaS UwaaS
September 24, 2020

OAuth2 & OpenID Connect with Spring Security

OAuth2 & OpenID Connect with Spring Security.
Details with hands-on practices.
For JSUG LT event: https://jsug.doorkeeper.jp/events/111811
Video Resource:
Sample App Preview: https://arcane-mesa-77496.herokuapp.com/
Sample App Repository: https://github.com/shutogeorgio/oauth2-spring-security
Official Spring Sample: https://github.com/spring-projects/spring-security/tree/5.3.4.RELEASE/samples/boot/oauth2login#okta-register-application

Avatar for UwaaS

UwaaS

September 24, 2020
Tweet

Other Decks in Technology

Transcript

  1. Explain it to Me Like I'm 5: Oauth2 and OpenID

    Digest for SpringOne Sep 2 – 4, 2020 Presenter, Shuto Uwai
  2. Who am I ? ・Tagbangers Intern ・Backend | Cloud Developer

    ・New Spring Developer https://speakerdeck.com/uwaas/oauth2-and-openid-connect-with-spring-security
  3. Goals ・ Understand OAuth2 deeply ・Implement spring security with OAuth2

    ・Integrate with OAuth2 Provider After this presentation, you will be able to ・Grab the concept of OpenID Connect
  4. Table Of Content 1. When & Why we use Oauth2

    ? 2. What is the Concept of Oauth2 ? 3. How to Protect Your Apps with Spring Security and 4. Demonstration OpenID Connect ?
  5. When Use Oauth2 as much as possible, as long as

    you would like to make applications secure , and maintainable !
  6. Build Your Own Cons ・Store user credentials safely ・Support LDAP//SAM

    integration ・Develop a password reset process ・Develop MFA by your own ・User feel annoyed to each application Pros with a unique password. ・Maybe .. customizable ??
  7. OpenID Connect / OAuth2 Pros Cons ・Maybe .. learning cost

    ? ・Store user credentials easily and safely ・Manages user registration easily ・Manage password reset process ・Implement MFA easily ・User can login with multiple applications with a single set of credentials
  8. 2. What is the Concept of OAuth2 ? ・Authentication vs.

    Authorization ・Roles ・Tokens ・Scopes ・Client Credentials ・Authorization Code
  9. Authentication vs. Authorization Authorization Authentication ・Identify who you are ・Must

    Prove your identity ・What are you allowed to do ・What API resources can you access
  10. Authorization Examples If you are in AWS environment, the access

    distribution would be... Administrator Developer Biz ・Have all access (Include billing access) ・Have access to create, delete, edit resources ・Only have access to read resources.
  11. Roles OAuth2 Role Regard Target Resource Owner / Resource I

    am / Jacket Resource Server Locker Authorization Server Lock Client / Application Your friend Locker (Resource Server) Lock (Authorization Server) Jacket (Resource) Would you mind letting me use your Jacket, bro ? Friend (Client)
  12. Scopes ・A scope Similar with a Spring Security role or

    a permission To make more specific ..
  13. Dive into Scopes A Job Role ・Like, manager, chef, server,

    dish wash etc.. ・A permitted authority or action ・Often dot separated: eat.cookies ・Google calendar URLs: https://www.googleapis.com/auth/calendar.readonly
  14. 3. How to Protect Your Apps with Spring Security and

    OpenID Connect ? Before going deeply …..
  15. OpenID Connect is….. Features ・Confidential, secure & browser based ・Not

    access a resource directly so that we get id ・Hybrid flow with id tokens instead of access tokens. token instead of an access token.
  16. OpenID's Metaphor Theme Park (Resource) Ticket (Access Token) You (Client)

    Wrist Band (ID Token) You with wrist Band (Client with ID token ) You are allow to enter ! Ticket gate (Open ID)
  17. OpenID Connect With Spring Security Spring Security's OAuth Support Spring

    Security OAuth There are mainly two types of modules.. ・This module is deprecated since this module is End-of-Life. More Detail: Link Support three integrations below ・Login ・Client ・Resource Server
  18. Demo Step By Step Guide vol.1 Step 1: Create Spring

    Boot App with Spring Security, OAuth2 Client & Spring Web Starters from here. Step 2: Create an OAuth2 client with GitHub For configuration, please set up Homepage URL and Authorization callback URL like right sample.
  19. Demo Step By Step Guide vol.2 Step 3: Configure application.properties

    or application.yml like below Step 4: Add a Controller & Endpoint: Create HomeController.java and code like this Step 5: Start application with: ./mvnw spring-boot:run
  20. Debugging & Resources Debugging 1. Add logging.level.org.springframework.security =debug and debug=true

    at your application.properties or application.yml 2. Add spring-boot-starter-actuator at your pom.xml 3. When you hit http://localhost:8080/actuator, you see like this
  21. External & Demo Resources Official Spring Security x OAuth2 Sample:

    See More Demo GitHub repository: https://github.com/shutogeorgio/oauth2-spring-security Demo App Preview: https://arcane-mesa-77496.herokuapp.com/
  22. Conclusion ・OpenID & OAuth2 are awesome ! ・Try OAuth2 yourself

    ! ・ Please be aware of your app's security with OAuth2