Added by: Sam Deering





Stars: 4

Watchers: 4

Forks: 1

Module Description


This repo contains a Rails API Framwork with PostGres and an Angular Client. Only the necessary gems/packages have been added to make Device/OAuth2 work together, everything else is untouched. I hope you'll find this helpful in getting a decoupled application going, especially the decioupled auth. Please report any bugs you find through pull request, thank you!!


Basic Rails API install with a Postgresql database. Only the necessary gems/code have been added to make Device/OAuth2 work, everything else is untouched.

#### Setup: - You'll want to replace the name of this project (SkeletonRailsApi) with the name of your project and DB. - Renaming is not neccesary to get this going, you'll want to rename if you use this skeleton for a project - In /config/application.rb - Rename ```module SkeletonRailsApi``` to your app name - In /config/database.yml rename the following, replace skeleton-rails-api with your app name - database: ``` skeleton-rails-api_development ``` - database: ```skeleton-rails-api_test``` - database: ```skeleton-rails-api_production``` - username: ```skeleton-rails-api``` - password: ```<%= ENV['SKELETON-RAILS-API_DATABASE_PASSWORD'] %>``` - In /config/initializers/secret_token.rb rename: ```SkeletonRailsApi::Application.config.secret_token = 'SOME SECRET TOKEN'``` - Make sure your Gemfile contains the OAuth gem of choice i.e: ``` gem 'omniauth-github' gem 'omniauth-facebook' gem 'omniauth-google-oauth2' ``` - Run the following: - ```Bundle install``` - ```rails g devise_token_auth:install User auth``` - ```Sets up model and migrations, db fields for User model``` - ```Sets up a route called auth``` - ```rake db:create``` - ```rake db:migrate``` - .ENV File - Create a .env file in your root directory - add your keys for your OAuth provider of choice - Set the ENV variable names for the auth provider you’re using in config/initializers/omniauth.rb (See: "OmniAuth provider settings” in https://github.com/lynndylanhurley/devise_token_auth for example )

Angular Client

This was also left as bare bones as possible and only includes the necessary code/scripts to work with Device/OAuth/RailsAPI.


  • Renaming
    • In index HTML
      • <html lang='en' ng-app='yourAppName'> yourAppName can be changed to...your apps name
      • <body ng-controller='mainCtrl'></body> mainCtrl can be changed but not necessary
      • <button ng-click="authenticate('google')"> 'google' can be replaced with the OAuth provider of your choice
    • In /js/controllers.js
      • angular.module('yourAppName', ['ng-token-auth']); yourAppName should match the app name you set in the HTML tag of index.html
      • var yourApp on line one, line 3, and line 9 can be changed to whatever you like.
      • $auth.authenticate('google') Google can be replaced with the OAuth Provider of choice - see https://github.com/lynndylanhurley/ng-token-auth#api
      • Put in the address of your API's server on line 5 apiUrl: 'http://localhost:3000'

Runnig the servers

From your rails api directory use the standard rails s
From terminal in your Angular root directory, you can simply use python to serve the index.thml python -m SimpleHTTPServer 9393

Other Notes

You need to configured your OAuth Provider for keys (google, fb, twitter) and setup your redirect from their site (see "OmniAuth provider settings” in https://github.com/lynndylanhurley/devise_token_auth )

In your rails API, when you move to Production you MUST change origins '*' resource '*' in your /config/application.rb to be the address of your Client Server otherwise anyone can hit your API

Any questions for the rails-api devise/oauth go to: https://github.com/lynndylanhurley/devise_token_auth
Any questions for the Angular devise/oauth go to: https://github.com/lynndylanhurley/ng-token-auth

I take absolutely no responsibility for this working well or terribly in your application. You should have a general understanding of what this code is doing and use the resources linked above to understand the Devise Token Auth and ng_Auth.

Module stats last updated: 2015-06-28 11:04:52

Disclaimer: Some data on this page may have been gathered from the authors GitHub respository. If you see any mistakes or outdated information please let us know. Thanks!