title: User Registration & Login | SSO using Spring Security OAuth 2.0
body: <p>I am trying to implement user registration and log in flow | SSO using Spring Security Oauth 2.0 and Google as the authentication provider.</p>
  
  <ul>
  <li>How should I initiate registration and login flow? What filter needs to be applied?</li>
  <li><p>In registration flow, I will needs user's details (name, email) that are part of successful authorization response, to be persisted in my local database. How do I handle that?</p></li>
  <li><p>What's the purpose of oauth2:client id="oauth2ClientFilter"  ?</p></li>
  </ul>
  
  <p>This is how my application context file looks like:-</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/mvc"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xmlns:beans="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context"
  xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:c="http://www.springframework.org/schema/c"
  xmlns:security="http://www.springframework.org/schema/security"
  xmlns:oauth2="http://www.springframework.org/schema/security/oauth2"
  xsi:schemaLocation="http://www.springframework.org/schema/jdbc  http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
      http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2.xsd
      http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
      http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
  &lt;!-- DispatcherServlet Context: defines this servlet's request-processing 
      infrastructure --&gt;
  
  &lt;!-- Enables the Spring MVC @Controller programming model --&gt;
  &lt;annotation-driven /&gt;
  
  &lt;!-- Handles HTTP GET requests for /resources/** by efficiently serving 
      up static resources in the ${webappRoot}/resources directory --&gt;
  &lt;resources mapping="/resources/**" location="/resources/" /&gt;
  
  &lt;!-- Resolves views selected for rendering by @Controllers to .jsp resources 
      in the /WEB-INF/views directory --&gt;
  &lt;beans:bean
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;beans:property name="prefix" value="/WEB-INF/views/" /&gt;
      &lt;beans:property name="suffix" value=".jsp" /&gt;
  &lt;/beans:bean&gt;
  
  &lt;context:component-scan base-package="com.samsoft.spring" /&gt;
  
  &lt;!-- ================================================== SECURITY START ================================================== --&gt;
  
  &lt;security:http security="none" pattern="/" /&gt;
  &lt;security:http security="none" pattern="/resources/**" /&gt;
  &lt;security:global-method-security
      secured-annotations="enabled" /&gt;
  
  &lt;security:http auto-config="true"&gt;
      &lt;security:intercept-url pattern="/**"
          requires-channel="https" access="IS_AUTHENTICATED_FULLY" /&gt;
      &lt;security:custom-filter ref="oauth2ClientFilter"
          after="EXCEPTION_TRANSLATION_FILTER" /&gt;
  &lt;/security:http&gt;
  &lt;oauth2:client id="oauth2ClientFilter" /&gt;
  
  &lt;oauth2:resource id="googleOauth2Resource" type="authorization_code"
      client-id="530420474177-clientid.apps.googleusercontent.com"
      client-secret="client-secret-here" access-token-uri="https://accounts.google.com/o/oauth2/token"
      user-authorization-uri="https://accounts.google.com/o/oauth2/auth"
      scope="https://www.googleapis.com/auth/calendar"
      client-authentication-scheme="form"
      pre-established-redirect-uri="https://ohad.sealdoc.com/oauth2-client/hello" /&gt;
  
  &lt;oauth2:rest-template id="googleOauthRestTemplate"
      resource="googleOauth2Resource" /&gt;
  
  &lt;security:authentication-manager&gt;
      &lt;security:authentication-provider&gt;
          &lt;security:user-service&gt;
              &lt;security:user name="test" authorities="ROLE_USER" password="test"/&gt;
          &lt;/security:user-service&gt;
      &lt;/security:authentication-provider&gt;
  &lt;/security:authentication-manager&gt;
  
  
  
  &lt;!-- ================================================== SECURITY END ================================================== --&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I did implemented same use case using Spring Security OpenID by:-</p>
  
  <ol>
  <li>Declaring openid:form tag with exchange attributed configured</li>
  <li>Extend the UserDetailsService as described <a href="https://stackoverflow.com/questions/10927633/spring-security-openid-userdetailsservice-authenticationuserdetailsservice/16571653#16571653">here</a>.</li>
  </ol>
  
  <p>I am looking for equivalent configuration for Oauth 2.0.</p>