Oauth2 Auth (Google Login)

ShipClojure Datom uses reitit and ring for handling API calls. All of the middleware and configuration is done through ring. Reitit is used only for the final routing part where needed.

I chose this architecture because ring & reitit have different approaches to middleware configuration, that builds confusion when trying to mix them together. You cannot have one without the other as ring is the underlying framework that transforms requests and responses to and from clojure maps, and reitit is just a router based on the content of the request map.

ShipClojure provides OAuth2 support for any login providers. By default, the Google provider is already setup.

Setting up Google login

Follow the steps here to create a google application and get your client-id & client-secret.

Important: Make sure the redirect URI set-up in your application matches the format /oauth2/:provider/callback which is the default for shipclojure

Add these properties to ~/resources/.secrets.edn under [:oauth2/connection-providers :connection.provider/google] {:client-id "123" :client-secret" "123"}

That's it! Your google login should be ready

Adding a new Oauth2 Provider

  1. Add the new entry in system.edn under :oauth2/providers

  2. Add the client secrets (:client-id & :client-secret) in your resources/.{prod|dev}-secrets.edn file

    {:oauth2/connection-providers
     {:connection.provider/google {:client-id "public client id"
                                   :client-secret "client secret"}
      :new-provider {:client-id "public client id"
                     :client-secret "secret shhh!"}}}
    
  3. Test your connection by visiting /oauth2/:provider and if everything was setup correctly, your new provider should work