Class Oauth2Controller

  • @RestController
    public class Oauth2Controller
    extends ApiBase
    Oauth2 login is completely handled by spring security, this is just callback once it's all done. Client's identity is something like joe:facebook, but hashed. Login name must match the stored identity. After login, user's Client object is stored in HttpSession, under key specified by clientFactory.clientAttribute() (local-user-name by default).
    • Field Summary

      Modifier and Type Field Description
      static String PATH  
    • Constructor Summary

      Constructor Description
      Oauth2Controller​( clientRegistrationRepository)  
    • Constructor Detail

      • Oauth2Controller

        public Oauth2Controller​(@Autowired
    • Method Detail

      • providers

        public Map<String,​String> providers()
        List of OAuth2 registered authentication providers.
        key-value pair of id and name, as declared in
      • setProvider

        public org.springframework.http.ResponseEntity<String> setProvider​(javax.servlet.http.HttpSession session,
                                                                           javax.servlet.http.HttpServletRequest request)
        First step in Oauth2 Authentication is to obtain valid authentication provider id. This is never called directly though, the browser is redirected here from the login page. Obtains the provider id from the original request and sends browser redirect.
      • login

        public org.springframework.http.ResponseEntity<String> login​(String name,
                                                                     String provider,
                                                                     String avatar,
                                                                     javax.servlet.http.HttpSession session,
                                                                     javax.servlet.http.HttpServletRequest request)
        This endpoint requires both user name and authentication provider id (fb, github, google... as defined in app properties file). The framework then performs authentication through a series of on-site and off-site redirects. Only after successful Oauth2 authentication with external provider, this method fetches or creates the Client object, and redirect back to the referring page. Client object is stored in HttpSession, under key specified by clientFactory.clientAttribute().
        name - Login name of the user, local
        provider - Oauth2 authentication provider id , as registered in properties file (e.g. github, facebook, google)
        avatar - Optional avatar URI, used only when creating a new user
      • callback

        public void callback​(String code,
                             String state,
                             javax.servlet.http.HttpServletRequest request)