Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base: c2f3857405
...
compare: b08f51b4c8
Checking mergeability… Don't worry, you can still create the pull request.
  • 9 commits
  • 7 files changed
  • 0 commit comments
  • 1 contributor
View
4 Gemfile
@@ -2,14 +2,12 @@ source :rubygems
gem "sinatra"
gem "thin"
gem "rack-ssl"
-gem "encrypted_cookie"
gem "haml"
gem "omniauth"
-gem "omniauth-salesforce", ">=1.0.3"
+gem "omniauth-salesforce"
group :development do
gem "wirble"
gem "foreman"
gem "heroku"
- gem "sqlite3"
end
View
6 Gemfile.lock
@@ -3,7 +3,6 @@ GEM
specs:
addressable (2.2.8)
daemons (1.1.4)
- encrypted_cookie (0.0.4)
eventmachine (0.12.10)
faraday (0.8.0)
multipart-post (~> 1.1)
@@ -48,7 +47,6 @@ GEM
rack (~> 1.3, >= 1.3.4)
rack-protection (~> 1.1, >= 1.1.2)
tilt (~> 1.3, >= 1.3.3)
- sqlite3 (1.3.6)
thin (1.3.1)
daemons (>= 1.0.9)
eventmachine (>= 0.12.6)
@@ -61,14 +59,12 @@ PLATFORMS
ruby
DEPENDENCIES
- encrypted_cookie
foreman
haml
heroku
omniauth
- omniauth-salesforce (>= 1.0.3)
+ omniauth-salesforce
rack-ssl
sinatra
- sqlite3
thin
wirble
View
29 lib/app.rb
@@ -1,5 +1,4 @@
require "sinatra/base"
-require "encrypted_cookie"
require "rack/ssl" unless ENV['RACK_ENV'] == "development"
require "haml"
require "omniauth"
@@ -8,6 +7,7 @@
class OmniAuthSalesforceExample < Sinatra::Base
configure do
+ enable :logging
set :app_file, __FILE__
set :root, File.expand_path("../..",__FILE__)
set :port, ENV['PORT']
@@ -19,12 +19,14 @@ class OmniAuthSalesforceExample < Sinatra::Base
use Rack::Session::Pool
OmniAuth.config.on_failure do |env|
- p "#{env['omniauth.error'].class.to_s}: #{env['omniauth.error'].message}"
- p "code: #{env['omniauth.error'].code}"
- p "response: #{env['omniauth.error'].response}"
- env['omniauth.error'].backtrace.each{|b| p b}
- p env['omniauth.error'].response.inspect if env['omniauth.error'].respond_to?(:response)
- [302, {'Location' => '/auth/failure'}, ['302 Redirect']]
+ [302,
+ {'Location' => env['SCRIPT_NAME'] +
+ OmniAuth.config.path_prefix +
+ "/failure?message=" +
+ env['omniauth.error'].code + ": " + env['omniauth.error'].description,
+ 'Content-Type'=> 'text/html'},
+ []
+ ]
end
use OmniAuth::Builder do
@@ -42,6 +44,10 @@ class OmniAuthSalesforceExample < Sinatra::Base
ENV['DATABASE_DOT_COM_SECRET']
end
+ before do
+ logger.info "hit: #{request.path_info}"
+ end
+
post '/authenticate' do
provider = sanitize_provider(params[:options]['provider'])
auth_params = {
@@ -57,12 +63,19 @@ class OmniAuthSalesforceExample < Sinatra::Base
request.env['rack.session'] = {}
redirect '/'
end
-
+
+ get '/auth/failure' do
+ haml :error, :locals => { :message => params[:message] }
+ end
+
get '/auth/:provider/callback' do
session[:auth_hash] = env['omniauth.auth']
redirect '/' unless session[:auth_hash] == nil
end
+ get '/error' do
+ end
+
get '/*' do
haml :index
end
View
BIN  public/favicon.ico
Binary file not shown
View
4 views/error.haml
@@ -0,0 +1,4 @@
+%div{:"data-role" => "header", :"data-theme" => "e"}
+ %h1 Error Occurred!
+%div{:class => "ui-body ui-body-e"}
+ %p #{message}
View
129 views/index.haml
@@ -1,76 +1,53 @@
-!!! 5
-%html{ :lang => "en"}
- %head
- %title= "omniauth-salesforce-example"
- %meta{ :name => "viewport", :content => "width=device-width, initial-scale=1"}
- %link{ :href => url("/jquery.mobile-1.1.0.css"), :media => "screen", :rel => "stylesheet", :type => "text/css" }
- %script{ :src => url("/jquery-1.7.2.min.js")}
- %script{ :src => url("/jquery.mobile-1.1.0.js")}
- %body
- %div{ :id => "foo", :"data-role" => "page", :"data-title" => "omniauth-salesforce-example"}
- %div{ :"data-role" => "header"}
- %h1 omniauth-salesforce-example
- %div{ :"data-role" => "content"}
- - if session[:auth_hash] == nil
- %h3 You are NOT authenticated.
- %a{:"data-role" => "button", :"data-ajax" => "false", :href => "#", :onclick => "document.authenticate_form.submit();"} Authenticate using your salesforce credentials
- %form{:id => "authenticate_form", :name => "authenticate_form", :action => "/authenticate", :method => "post"}
- %div{:class => "ui-body"}
- %div{:"data-role" => "collapsible", :"data-collapsed" => "true", :"data-theme" => "b", :"data-content-theme" => "c"}
- %h3 Authentication Options
- %p
- %div{:"data-role" => "fieldcontain"}
- %fieldset{:"data-role" => "controlgroup"}
- %legend Environment
- %input{:type => "radio", :name => "options[provider]", :id => "options[provider]-1", :value => "salesforce", :checked => true}
- %label{:for => "options[provider]-1"} production (login.salesforce.com)
- %input{:type => "radio", :name => "options[provider]", :id => "options[provider]-2", :value => "salesforcesandbox"}
- %label{:for => "options[provider]-2"} sandbox (test.salesforce.com)
- %input{:type => "radio", :name => "options[provider]", :id => "options[provider]-3", :value => "salesforceprerelease"}
- %label{:for => "options[provider]-3"} pre-release (prerellogin.pre.salesforce.com)
- %input{:type => "radio", :name => "options[provider]", :id => "options[provider]-4", :value => "databasedotcom"}
- %label{:for => "options[provider]-4"} database.com (login.database.com)
- %div{:"data-role" => "fieldcontain"}
- %fieldset{:"data-role" => "controlgroup"}
- %legend Display
- %input{:type => "radio", :name => "options[display]", :id => "options[display]-1", :value => "page", :checked => true}
- %label{:for => "options[display]-1"} page: full-page authorization screen
- %input{:type => "radio", :name => "options[display]", :id => "options[display]-2", :value => "popup"}
- %label{:for => "options[display]-2"} popup: compact dialog optimized for modern web browser popup windows.
- %input{:type => "radio", :name => "options[display]", :id => "options[display]-3", :value => "touch"}
- %label{:for => "options[display]-3"} touch: mobile-optimized dialog designed for modern smartphones, such as Android and iPhone.
- %fieldset{:"data-role" => "controlgroup"}
- %legend Access Level
- - default_scopes = Set.new(%w(api id refresh_token))
- - %w(api chatter_api full id refresh_token visualforce web).each do |scope|
- %input{:type => "checkbox", :name => "options[scope|#{scope}]", :id => "options[scope|#{scope}]", :class => "custom", :checked => default_scopes.include?(scope)}
- %label{:for => "options[scope|#{scope}]"} #{scope}
- %div{:"data-role" => "fieldcontain"}
- %label{:for => "options[immediate]"} Immediate
- %select{:id => "options[immediate]", :name => "options[immediate]", :"data-role" => "slider"}
- %option{:value => "false"} No
- %option{:value => "true"} Yes
- - else
- %h3 You've been authenticated as:
- %div{:class => "ui-body"}
- %img{:align => "left", :src => session[:auth_hash][:info][:image], :style => "margin-right: 12px"}
- %strong #{session[:auth_hash][:info][:name]}
- %br
- #{session[:auth_hash][:extra][:username]}
- %br
- #{session[:auth_hash][:extra][:organization_id]}
- %br
- #{session[:auth_hash][:extra][:instance_url]}
- %a{:"data-role" => "button", :"data-ajax" => "false", :href => "/unauthenticate"} Log out (from this app only, not salesforce.com)
- %div{:class => "ui-body"}
- = htmlize_hash("ENV['omniauth.auth']",session[:auth_hash])
- %a{:href => "https://github.com/richardvanhook/omniauth-salesforce-example"}
- %img{:style => "position: absolute; top: 0; right: 0; border: 0;", :src => "https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png", :alt => "Fork me on GitHub"}
-:javascript
- var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
- document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
-:javascript
- try{
- var pageTracker = _gat._getTracker("UA-31738053-1");
- pageTracker._trackPageview();
- } catch(err) {}
+- if session[:auth_hash] == nil
+ %h3 You are NOT authenticated.
+ %a{:"data-role" => "button", :"data-ajax" => "false", :href => "#", :onclick => "document.authenticate_form.submit();"} Authenticate using your salesforce credentials
+ %form{:id => "authenticate_form", :name => "authenticate_form", :action => "/authenticate", :method => "post"}
+ %div{:class => "ui-body"}
+ %div{:"data-role" => "collapsible", :"data-collapsed" => "true", :"data-theme" => "b", :"data-content-theme" => "c"}
+ %h3 Authentication Options
+ %p
+ %div{:"data-role" => "fieldcontain"}
+ %fieldset{:"data-role" => "controlgroup"}
+ %legend Environment
+ %input{:type => "radio", :name => "options[provider]", :id => "options[provider]-1", :value => "salesforce", :checked => true}
+ %label{:for => "options[provider]-1"} production (login.salesforce.com)
+ %input{:type => "radio", :name => "options[provider]", :id => "options[provider]-2", :value => "salesforcesandbox"}
+ %label{:for => "options[provider]-2"} sandbox (test.salesforce.com)
+ %input{:type => "radio", :name => "options[provider]", :id => "options[provider]-3", :value => "salesforceprerelease"}
+ %label{:for => "options[provider]-3"} pre-release (prerellogin.pre.salesforce.com)
+ %input{:type => "radio", :name => "options[provider]", :id => "options[provider]-4", :value => "databasedotcom"}
+ %label{:for => "options[provider]-4"} database.com (login.database.com)
+ %div{:"data-role" => "fieldcontain"}
+ %fieldset{:"data-role" => "controlgroup"}
+ %legend Display
+ %input{:type => "radio", :name => "options[display]", :id => "options[display]-1", :value => "page", :checked => true}
+ %label{:for => "options[display]-1"} page: full-page authorization screen
+ %input{:type => "radio", :name => "options[display]", :id => "options[display]-2", :value => "popup"}
+ %label{:for => "options[display]-2"} popup: compact dialog optimized for modern web browser popup windows.
+ %input{:type => "radio", :name => "options[display]", :id => "options[display]-3", :value => "touch"}
+ %label{:for => "options[display]-3"} touch: mobile-optimized dialog designed for modern smartphones, such as Android and iPhone.
+ %fieldset{:"data-role" => "controlgroup"}
+ %legend Access Level
+ - default_scopes = Set.new(%w(api id refresh_token))
+ - %w(api chatter_api full id refresh_token visualforce web).each do |scope|
+ %input{:type => "checkbox", :name => "options[scope|#{scope}]", :id => "options[scope|#{scope}]", :class => "custom", :checked => default_scopes.include?(scope)}
+ %label{:for => "options[scope|#{scope}]"} #{scope}
+ %div{:"data-role" => "fieldcontain"}
+ %label{:for => "options[immediate]"} Immediate
+ %select{:id => "options[immediate]", :name => "options[immediate]", :"data-role" => "slider"}
+ %option{:value => "false"} No
+ %option{:value => "true"} Yes
+- else
+ %h3 You've been authenticated as:
+ %div{:class => "ui-body"}
+ %img{:align => "left", :src => session[:auth_hash][:info][:image], :style => "margin-right: 12px"}
+ %strong #{session[:auth_hash][:info][:name]}
+ %br
+ #{session[:auth_hash][:extra][:username]}
+ %br
+ #{session[:auth_hash][:extra][:organization_id]}
+ %br
+ #{session[:auth_hash][:extra][:instance_url]}
+ %a{:"data-role" => "button", :"data-ajax" => "false", :href => "/unauthenticate"} Log out (from this app only, not salesforce.com)
+ %div{:class => "ui-body"}
+ = htmlize_hash("ENV['omniauth.auth']",session[:auth_hash])
View
24 views/layout.haml
@@ -0,0 +1,24 @@
+!!! 5
+%html{ :lang => "en"}
+ %head
+ %title= "omniauth salesforce example"
+ %meta{ :name => "viewport", :content => "width=device-width, initial-scale=1"}
+ %link{ :href => url("/jquery.mobile-1.1.0.css"), :media => "screen", :rel => "stylesheet", :type => "text/css" }
+ %script{ :src => url("/jquery-1.7.2.min.js")}
+ %script{ :src => url("/jquery.mobile-1.1.0.js")}
+ %body
+ #page{:"data-role" => "page", :"data-title" => "omniauth salesforce example"}
+ #header{ :"data-role" => "header"}
+ %h1 omniauth salesforce example
+ #content{ :"data-role" => "content"}
+ = yield
+ %a{:href => "https://github.com/richardvanhook/omniauth-salesforce-example"}
+ %img{:style => "position: absolute; top: 0; right: 0; border: 0;", :src => "https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png", :alt => "Fork me on GitHub"}
+:javascript
+ var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
+ document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
+:javascript
+ try{
+ var pageTracker = _gat._getTracker("UA-31738053-1");
+ pageTracker._trackPageview();
+ } catch(err) {}

No commit comments for this range

Something went wrong with that request. Please try again.