README.adoc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. = Samples
  2. [[default-sample]]
  3. == Default Sample
  4. The default sample provides the minimal configuration to get started with Spring Authorization Server.
  5. [[demo-sample]]
  6. == Demo Sample
  7. The demo sample provides custom configuration for various features implemented by Spring Authorization Server.
  8. [[run-demo-sample]]
  9. === Run the Sample
  10. * Run Authorization Server -> `./gradlew -b samples/demo-authorizationserver/samples-demo-authorizationserver.gradle bootRun`
  11. * Run Client -> `./gradlew -b samples/demo-client/samples-demo-client.gradle bootRun`
  12. * Run Resource Server -> `./gradlew -b samples/messages-resource/samples-messages-resource.gradle bootRun`
  13. * Go to `http://127.0.0.1:8080`
  14. ** Login with credentials -> user1 \ password
  15. [[configuring-social-login]]
  16. === Configuring Social Login
  17. The demo sample may be configured to provide social login capability.
  18. [[google-login]]
  19. ==== Login with Google
  20. This section shows how to configure Google as a social login provider.
  21. [[google-initial-setup]]
  22. ===== Initial setup
  23. To use Google's OAuth 2.0 authentication system for login, you must set up a project in the Google API Console to obtain OAuth 2.0 credentials.
  24. NOTE: https://developers.google.com/identity/protocols/OpenIDConnect[Google's OAuth 2.0 implementation] for authentication conforms to the
  25. https://openid.net/connect/[OpenID Connect 1.0] specification and is https://openid.net/certification/[OpenID Certified].
  26. Follow the instructions on the https://developers.google.com/identity/protocols/OpenIDConnect[OpenID Connect] page, starting in the section, "Setting up OAuth 2.0".
  27. After completing the "Obtain OAuth 2.0 credentials" instructions, you should have a new OAuth Client with credentials consisting of a Client ID and a Client Secret.
  28. [[google-redirect-uri]]
  29. ===== Setting the redirect URI
  30. The redirect URI is the path in the application that the end-user's user-agent is redirected back to after they have authenticated with Google
  31. and have granted access to the OAuth Client _(created in the previous step)_ on the Consent page.
  32. In the "Set a redirect URI" sub-section, ensure that the *Authorized redirect URIs* field is set to `http://localhost:9000/login/oauth2/code/google-idp`.
  33. TIP: The default redirect URI template is `{baseUrl}/login/oauth2/code/{registrationId}`.
  34. The *_registrationId_* is a unique identifier for the `ClientRegistration`.
  35. [[google-application-config]]
  36. ===== Configure application.yml
  37. Now that you have a new OAuth Client with Google, you need to configure the application to use the OAuth Client for the _authentication flow_. To do so:
  38. . Go to `application.yml` and set the following configuration:
  39. +
  40. [source,yaml]
  41. ----
  42. spring:
  43. security:
  44. oauth2:
  45. client:
  46. registration: <1>
  47. google-idp: <2>
  48. provider: google
  49. client-id: google-client-id
  50. client-secret: google-client-secret
  51. ----
  52. +
  53. .OAuth Client properties
  54. ====
  55. <1> `spring.security.oauth2.client.registration` is the base property prefix for OAuth Client properties.
  56. <2> Following the base property prefix is the ID for the `ClientRegistration`, such as google-idp.
  57. ====
  58. . Replace the values in the `client-id` and `client-secret` property with the OAuth 2.0 credentials you created earlier.
  59. Alternatively, you can set the following environment variables in the Spring Boot application:
  60. * `GOOGLE_CLIENT_ID`
  61. * `GOOGLE_CLIENT_SECRET`
  62. [[github-login]]
  63. ==== Login with GitHub
  64. This section shows how to configure GitHub as a social login provider.
  65. [[github-register-application]]
  66. ===== Register OAuth application
  67. To use GitHub's OAuth 2.0 authentication system for login, you must https://github.com/settings/applications/new[Register a new OAuth application].
  68. When registering the OAuth application, ensure the *Authorization callback URL* is set to `http://localhost:9000/login/oauth2/code/github-idp`.
  69. The Authorization callback URL (redirect URI) is the path in the application that the end-user's user-agent is redirected back to after they have authenticated with GitHub
  70. and have granted access to the OAuth application on the _Authorize application_ page.
  71. TIP: The default redirect URI template is `{baseUrl}/login/oauth2/code/{registrationId}`.
  72. The *_registrationId_* is a unique identifier for the `ClientRegistration`.
  73. [[github-application-config]]
  74. ===== Configure application.yml
  75. Now that you have a new OAuth application with GitHub, you need to configure the application to use the OAuth application for the _authentication flow_. To do so:
  76. . Go to `application.yml` and set the following configuration:
  77. +
  78. [source,yaml]
  79. ----
  80. spring:
  81. security:
  82. oauth2:
  83. client:
  84. registration: <1>
  85. github-idp: <2>
  86. provider: github
  87. client-id: github-client-id
  88. client-secret: github-client-secret
  89. ----
  90. +
  91. .OAuth Client properties
  92. ====
  93. <1> `spring.security.oauth2.client.registration` is the base property prefix for OAuth Client properties.
  94. <2> Following the base property prefix is the ID for the `ClientRegistration`, such as github-idp.
  95. ====
  96. . Replace the values in the `client-id` and `client-secret` property with the OAuth 2.0 credentials you created earlier.
  97. Alternatively, you can set the following environment variables in the Spring Boot application:
  98. * `GITHUB_CLIENT_ID`
  99. * `GITHUB_CLIENT_SECRET`