jgraycar / Kamaete-API

https://kamaete-api.herokuapp.com
0 stars 1 forks source link

Oauth2 Login #2

Open jgraycar opened 8 years ago

jgraycar commented 8 years ago

Enable Facebook (and eventually Google) omniauth login. This feature is supported out of the box by devise-token-auth, and just needs some configuration work on the server side.

Closely tied to Issue #3 on the client side repo.

jgraycar commented 8 years ago

Once a Facebook key and secret are obtained from the Facebook Developer's site (start here), they can be loaded into the ENV hash by creating the file config/local_env.yml and filling it like so:

# config/local_env.yml
FACEBOOK_KEY: "FACEBOOK_KEY_HERE"
FACEBOOK_SECRET: "FACEBOOK_SECRET_HERE"

You can test that this worked by booting up a rails console session and manually checking the ENV hash for that key.

$ spring rails c
Running via Spring preloader in process 63661
Loading development environment (Rails 5.0.0.rc1)
2.3.1 :001 > ENV['FACEBOOK_KEY']
 => "FACEBOOK_KEY_HERE" 
2.3.1 :002 > ENV['FACEBOOK_SECRET']
 => "FACEBOOK_SECRET_HERE" 

With that set up, make sure the config/local_env.yml file does not show up when you run git status! It should already be git-ignored, but you want to make sure it does not get committed or pushed, since those keys should be kept secret.

jgraycar commented 8 years ago

In config/routes.rb, you'll want to remove the skip: [:omniauth_callbacks] part of the mount_devise_token_auth_for 'User' line.