A simple demonstration of how to integrate google and facebook Oauth2 login functionality.
- Download the git repository
git clone https://github.com/jesse-greathouse/demotivational
- Change to the demotivational directory
cd demotivational
- The easiest way to run the application is with Docker. If you don't have Docker installed You will need to install docker on your host. Check the Official Docker Site on how to install Docker on your host.
- Run the configuration script
bin/configure-docker.sh
- The configuration script is interactive.
- Leave the options blank if you don't want to change them
- For this demonstration, I have created defaults for the google and facebook key strings, if you leave them blank, they will revert to safe defaults.
- Once you have the proper configuration, press Y to accept
- Run the "run" script
bin/run-docker.sh
- check http://localhost:3000/
- You may have changed the designated port during configuration. If that's the case, use the port you specified.
Alternatively there are scripts to install the application, directly, on OSX or Linux brands.
- Check the bin/ folder for an installation script on your platform
- e.g.: bin/install-osx.sh
When you first load the application in your web browser, it will redirect you to the /login screen because you do not yet have a session token.
When you select a provider a pop-up window will direct you to login at the provider of your choice.
- Please disable pop-up blockers for the purpose of this demonstration
Once you have logged in, the application will redirect you to the home page. A search will be conducted in the Google API, and a random demotivational image will be selected just for you!
When you press the logout button, you will be taken to the logout screen. Not much can be said about this. It will simply destroy your session and redirect you to the login page.
- The application uses a framework called Openresty.
- It puts Nginx together with LuaJIT to allow powerful Lua scripting from directly inside the Nginx workers.
- You can see from the source code of this file that this enables Lua scripting in the Nginx configuration.
- Under src/jgreathouse/demotivational/views.lua I have created methods for generating the application's views.
- I have created functions for handling sessions.
- I have also created endpoints for handling authentication via google or facebook.
- When the application receives authentication information, about the user and the user's token, it creates models of those domain objects, and saves them to the session.
- Because there are two available authentication providers, the application also uses adapters to conform the provider's domain models to its native domain models.
- The application uses a templating library made by Bungle
- The template files can be found under the web/ folder. There is a layout, and a simple content template for every view. It's fairly standard just like other templating engines.
- The UI uses standard jQuery and Bootstrap assets. I chose these UI tools because they can be accessed by a CDN and they aren't demanding in terms of setup.
- I have also included the standard JavaScript SDK's for Google and Facebook Oauth2.
- The JavaScript code that I used to handle this functionality was very boilerplate, taken directly from the docs of the respective SDKs.
- The method of Authentication is all on the front end. Once the front-end receives authentication information from the provider, the application signals that information to the back-end with xhr calls to the handler endpoints.