Skip to content

Commit

Permalink
Merge pull request #5 from sandrinodimattia/webapp-example
Browse files Browse the repository at this point in the history
Web application seed with Lock
  • Loading branch information
sandrinodimattia committed Feb 19, 2015
2 parents 9370428 + 1fa7a50 commit a5301d4
Show file tree
Hide file tree
Showing 74 changed files with 1,074 additions and 0 deletions.
17 changes: 17 additions & 0 deletions examples/ruby-on-rails-webapp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal

# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
.env
48 changes: 48 additions & 0 deletions examples/ruby-on-rails-webapp/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', group: :development
gem 'pry', group: :development
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

gem 'rails_12factor', group: :production

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development

gem 'omniauth', '~> 1.2'
gem 'omniauth-auth0', '~> 1.1'

gem 'dotenv', '~> 0.11.1', group: :development

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]
20 changes: 20 additions & 0 deletions examples/ruby-on-rails-webapp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#Auth0 + Ruby on Rails WebApp Seed
This is the seed project you need to use if you're going to create a regular WebApp with Ruby on Rails. If you want to build a Ruby On Rails API that will be used with a SPA or a Mobile device, please check this [other seed project](https://github.com/auth0/ruby-auth0/tree/master/examples/ruby-on-rails-api)

This example is deployed at Heroku at http://auth0-ror-webapp-sample.herokuapp.com/

#Running the example
In order to run the example you need to have ruby installed.

You also need to set the ClientSecret, ClientId, Domain and CallbackURL for your Auth0 app as enviroment variables with the following names respectively: AUTH0_CLIENT_SECRET, AUTH0_CLIENT_ID, AUTH0_DOMAIN and AUTH0_CALLBACK_URL.

For that, if you just create a file named .env in the directory and set the values like the following, the app will just work:

````bash
# .env file
AUTH0_CLIENT_SECRET=myCoolSecret
AUTH0_CLIENT_ID=myCoolClientId
AUTH0_DOMAIN=samples.auth0.com
AUTH0_CALLBACK_URL=http://localhost:3000/auth/auth0/callback
````
Once you've set those 4 enviroment variables, just run `rails s` and try calling [http://localhost:3000/](http://localhost:3000/)
28 changes: 28 additions & 0 deletions examples/ruby-on-rails-webapp/README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
== README

This README would normally document whatever steps are necessary to get the
application up and running.

Things you may want to cover:

* Ruby version

* System dependencies

* Configuration

* Database creation

* Database initialization

* How to run the test suite

* Services (job queues, cache servers, search engines, etc.)

* Deployment instructions

* ...


Please feel free to use a different markup language if you do not plan to run
<tt>rake doc:app</tt>.
6 changes: 6 additions & 0 deletions examples/ruby-on-rails-webapp/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

Rails.application.load_tasks
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require_tree .
10 changes: 10 additions & 0 deletions examples/ruby-on-rails-webapp/app/assets/javascripts/home.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var lock = new Auth0Lock('<%= Rails.application.secrets.auth0_client_id %>', '<%= Rails.application.secrets.auth0_domain %>');
function signin() {
lock.show({
callbackURL: 'http://localhost:3000/auth/auth0/callback', // use this in production '<%= Rails.application.secrets.auth0_callback_url %>'
responseType: 'code',
authParams: {
scope: 'openid profile'
}
});
}
114 changes: 114 additions & 0 deletions examples/ruby-on-rails-webapp/app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any styles
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
* file per style scope.
*
*= require_tree .
*= require_self
*/

body {
font-family: "proxima-nova", sans-serif;
text-align: center;
font-size: 300%;
font-weight: 100;
}
input[type=checkbox],
input[type=radio] {
position: absolute;
opacity: 0;
}
input[type=checkbox] + label,
input[type=radio] + label {
display: inline-block;
}
input[type=checkbox] + label:before,
input[type=radio] + label:before {
content: "";
display: inline-block;
vertical-align: -0.2em;
width: 1em;
height: 1em;
border: 0.15em solid #0074d9;
border-radius: 0.2em;
margin-right: 0.3em;
background-color: white;
}
input[type=radio] + label:before {
border-radius: 50%;
}
input[type=radio]:checked + label:before,
input[type=checkbox]:checked + label:before {
background-color: #0074d9;
box-shadow: inset 0 0 0 0.15em white;
}
input[type=radio]:focus + label:before,
input[type=checkbox]:focus + label:before {
outline: 0;
}
.btn {
font-size: 140%;
text-transform: uppercase;
letter-spacing: 1px;
border: 0;
background-color: #16214D;
color: white;
}
.btn:hover {
background-color: #44C7F4;
}
.btn:focus {
outline: none !important;
}
.btn.btn-lg {
padding: 20px 30px;
}
.btn:disabled {
background-color: #333;
color: #666;
}
h1,
h2,
h3 {
font-weight: 100;
}
#logo img {
width: 300px;
margin-bottom: 60px;
}
.home-description {
font-weight: 100;
margin: 100px 0;
}
h2 {
margin-top: 30px;
margin-bottom: 40px;
font-size: 200%;
}
label {
font-size: 100%;
font-weight: 300;
}
.btn-next {
margin-top: 30px;
}
.answer {
width: 70%;
margin: auto;
text-align: left;
padding-left: 10%;
margin-bottom: 20px;
}
.login-page .login-box {
padding: 100px 0;
}
pre {
text-align: left;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end
14 changes: 14 additions & 0 deletions examples/ruby-on-rails-webapp/app/controllers/auth0_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Auth0Controller < ApplicationController
def callback
# example request.env['omniauth.auth'] in https://github.com/auth0/omniauth-auth0#auth-hash
# id_token = session[:userinfo]['credentials']['id_token']
# store the user profile in session and redirect to root
session[:userinfo] = request.env['omniauth.auth']

redirect_to '/dashboard'
end

def failure
@error_msg = request.params['message']
end
end
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class DashboardController < SecuredController
def show
@user = session[:userinfo]
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class HomeController < ApplicationController
def show

end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class SecuredController < ApplicationController

before_action :logged_in_using_omniauth?

private

def logged_in_using_omniauth?
unless session[:userinfo].present?
redirect_to '/'
end
end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ApplicationHelper
end
2 changes: 2 additions & 0 deletions examples/ruby-on-rails-webapp/app/helpers/callback_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CallbackHelper
end
2 changes: 2 additions & 0 deletions examples/ruby-on-rails-webapp/app/helpers/dashboard_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module DashboardHelper
end
2 changes: 2 additions & 0 deletions examples/ruby-on-rails-webapp/app/helpers/home_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module HomeHelper
end
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="home">
<h2>Error <%= @error_msg %></h2>
<p><%= @omniauth_error %></p>
</div>
12 changes: 12 additions & 0 deletions examples/ruby-on-rails-webapp/app/views/dashboard/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="home">
<div class="container">
<div class="login-page clearfix">
<div class="logged-in-box auth0-box logged-in">
<h1 id="logo"><img src="//cdn.auth0.com/samples/auth0_logo_final_blue_RGB.png" /></h1>
<img class="avatar" src="<%= @user[:info][:image] %>"/>
<h2>Welcome <%= @user[:info][:name] %></h2>
<pre><%= JSON.pretty_generate(@user[:info]) %></pre>
</div>
</div>
</div>
</div>
17 changes: 17 additions & 0 deletions examples/ruby-on-rails-webapp/app/views/home/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<% content_for :cdn_code do %>
<%= javascript_include_tag '//cdn.auth0.com/js/lock-7.0.min.js' %>
<% end %>
<div class="home">
<div class="container">
<div class="login-page clearfix">
<div class="login-box auth0-box before">
<img src="https://i.cloudup.com/StzWWrY34s.png" />
<h3>Auth0 Example</h3>
<p>Zero friction identity infrastructure, built for developers</p>
<a class="btn btn-primary btn-lg btn-login btn-block" onclick="signin()">SignIn</a>
</div>
</div>
</div>
</div>


Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title>RubyOnRailsWebapp</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<%= yield :cdn_code %>
<%= stylesheet_link_tag '//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css' %>
<%= stylesheet_link_tag '//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css' %>
<%= javascript_include_tag '//use.typekit.net/iws6ohy.js' %>
<script type="text/javascript">try{Typekit.load();}catch(e){}</script>

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>

<%= yield %>

</body>
</html>
3 changes: 3 additions & 0 deletions examples/ruby-on-rails-webapp/bin/bundle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')
4 changes: 4 additions & 0 deletions examples/ruby-on-rails-webapp/bin/rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
4 changes: 4 additions & 0 deletions examples/ruby-on-rails-webapp/bin/rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
Rake.application.run
Loading

0 comments on commit a5301d4

Please sign in to comment.