Skip to content

Commit

Permalink
Update Gemfile, enable logging
Browse files Browse the repository at this point in the history
  • Loading branch information
fairchild committed Jan 5, 2012
1 parent 5aa43b0 commit 9caa5a1
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 74 deletions.
24 changes: 20 additions & 4 deletions Gemfile
@@ -1,6 +1,22 @@
source "http://rubygems.org" source :rubygems
gem 'rack', '1.3.6'
gem 'thin'
gem 'sinatra'
gem 'json'
gem 'omniauth'
gem 'omniauth-oauth2'
gem 'activesupport'
gem 'i18n'
gem 'rest-client'


# gem 'omniauth-att', :path => File.expand_path("./../../omniauth-att", __FILE__)
gem 'newrelic_rpm'
group :example do
gem 'omniauth-github'
gem 'omniauth-facebook'
gem 'omniauth-twitter'
end


gem 'rake' group :developent do
# Specify your gem's dependencies in omniauth-att.gemspec gem 'shotgun'
gemspec end
44 changes: 16 additions & 28 deletions Gemfile.lock
@@ -1,17 +1,3 @@
PATH
remote: .
specs:
omniauth-att (0.2)
activesupport
i18n
omniauth (~> 1.0)
omniauth-facebook
omniauth-github
omniauth-oauth2 (~> 1.0)
omniauth-twitter
sinatra
thin

GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
Expand All @@ -25,17 +11,12 @@ GEM
multipart-post (~> 1.1.3) multipart-post (~> 1.1.3)
rack (>= 1.1.0, < 2) rack (>= 1.1.0, < 2)
hashie (1.2.0) hashie (1.2.0)
heroku (2.17.0)
launchy (>= 0.3.2)
rest-client (~> 1.6.1)
rubyzip
term-ansicolor (~> 1.0.5)
i18n (0.6.0) i18n (0.6.0)
launchy (2.0.5) json (1.6.4)
addressable (~> 2.2.6)
mime-types (1.17.2) mime-types (1.17.2)
multi_json (1.0.4) multi_json (1.0.4)
multipart-post (1.1.4) multipart-post (1.1.4)
newrelic_rpm (3.3.1)
oauth (0.4.5) oauth (0.4.5)
oauth2 (0.5.2) oauth2 (0.5.2)
faraday (~> 0.7) faraday (~> 0.7)
Expand All @@ -56,20 +37,17 @@ GEM
omniauth (~> 1.0) omniauth (~> 1.0)
omniauth-twitter (0.0.7) omniauth-twitter (0.0.7)
omniauth-oauth (~> 1.0) omniauth-oauth (~> 1.0)
rack (1.4.0) rack (1.3.6)
rack-protection (1.2.0) rack-protection (1.2.0)
rack rack
rake (0.9.2.2)
rest-client (1.6.7) rest-client (1.6.7)
mime-types (>= 1.16) mime-types (>= 1.16)
rubyzip (0.9.5)
shotgun (0.9) shotgun (0.9)
rack (>= 1.0) rack (>= 1.0)
sinatra (1.3.2) sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6) rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2) rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3) tilt (~> 1.3, >= 1.3.3)
term-ansicolor (1.0.7)
thin (1.3.1) thin (1.3.1)
daemons (>= 1.0.9) daemons (>= 1.0.9)
eventmachine (>= 0.12.6) eventmachine (>= 0.12.6)
Expand All @@ -80,7 +58,17 @@ PLATFORMS
ruby ruby


DEPENDENCIES DEPENDENCIES
heroku activesupport
omniauth-att! i18n
rake json
newrelic_rpm
omniauth
omniauth-facebook
omniauth-github
omniauth-oauth2
omniauth-twitter
rack (= 1.3.6)
rest-client
shotgun shotgun
sinatra
thin
4 changes: 1 addition & 3 deletions README.md
Expand Up @@ -22,9 +22,7 @@


heroku config:add RACK_ENV=production heroku config:add RACK_ENV=production
heroku addons:add newrelic heroku addons:add newrelic
heroku addons:add redistogo:nano heroku addons:add redistogo:nano
heroku addons:add blitz:250



# config # config


Expand Down
2 changes: 2 additions & 0 deletions config.ru
Expand Up @@ -3,4 +3,6 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__),"lib"))
require "rubygems" require "rubygems"
require './example/example_omniauth_app.rb' require './example/example_omniauth_app.rb'


puts "using :site => #{ENV['ATT_BASE_DOMAIN']}"

run SinatraApp run SinatraApp
81 changes: 47 additions & 34 deletions example/example_omniauth_app.rb
Expand Up @@ -10,6 +10,7 @@


class SinatraApp < Sinatra::Base class SinatraApp < Sinatra::Base
configure do configure do
set :logging, true
set :sessions, true set :sessions, true
set :inline_templates, true set :inline_templates, true
end end
Expand All @@ -29,14 +30,21 @@ def db
provider :github, (ENV['GITHUB_CLIENT_ID']||'b6ce639ebd5618ca4d52'), (ENV['GITHUB_CLIENT_SECRET']||'ef8b9abe468c2021d1e829f566091446375ea181') provider :github, (ENV['GITHUB_CLIENT_ID']||'b6ce639ebd5618ca4d52'), (ENV['GITHUB_CLIENT_SECRET']||'ef8b9abe468c2021d1e829f566091446375ea181')
provider :facebook, (ENV['FACEBOOK_CLIENT_ID']||'290594154312564'),(ENV['FACEBOOK_CLIENT_SECRET']||'a26bcf9d7e254db82566f31c9d72c94e') provider :facebook, (ENV['FACEBOOK_CLIENT_ID']||'290594154312564'),(ENV['FACEBOOK_CLIENT_SECRET']||'a26bcf9d7e254db82566f31c9d72c94e')
provider :twitter, 'cO23zABqRXQpkmAXa8MRw', 'TwtroETQ6sEDWW8HEgt0CUWxTavwFcMgAwqHdb0k1M' provider :twitter, 'cO23zABqRXQpkmAXa8MRw', 'TwtroETQ6sEDWW8HEgt0CUWxTavwFcMgAwqHdb0k1M'
provider :att, 'client_id', 'client_secret', :callback_url => ENV['BASE_DOMAIN'] || 'http://localhost:9393' provider :att, 'client_id', 'client_secret', :callback_url => "#(ENV['BASE_DOMAIN'] || 'http://localhost:9393')"
end end


get '/' do get '/' do
erb :index url = request.env['REQUEST_URI']
url = url[0..-2] if url[-1] == '/'
erb "
<a href='#{url}/auth/github'>Login with Github</a><br>
<a href='#{url}/auth/facebook'>Login with facebook</a><br>
<a href='#{url}/auth/twitter'>Login with twitter</a><br>
<a href='#{url}/auth/att'>Login with att-foundry</a>"
end end


get '/auth/:provider/callback' do
get '/auth/:provider/callback' do
db[:access_token] = request.env['omniauth.auth']['credentials']['token'] db[:access_token] = request.env['omniauth.auth']['credentials']['token']
erb "<h1>#{params[:provider]}</h1> erb "<h1>#{params[:provider]}</h1>
<pre>#{JSON.pretty_generate(request.env['omniauth.auth'])}</pre>" <pre>#{JSON.pretty_generate(request.env['omniauth.auth'])}</pre>"
Expand All @@ -58,33 +66,13 @@ def db
end end


get '/doc' do get '/doc' do
erb <<-EOD erb :docs
<h2>Authentication docs page</h2>
<p>This is a sample application that shows how the authentication mechanism works.</p>
<p>It is incredibly simple and mimicks the OAuth2 flow. Firstly, the application must have
a <code>client_id</code> and a <code>client_secret</code>. When the application wants to get
an authenticated user, they can simply redirect the user with their <code>client_id</code> and a <code>redirect_uri</code> to
the foundry auth page at: #{auth_url}/login.
The foundry auth will take care of the login and redirecting the user back to the <code>redirect_uri</code> (provided it matches the one that the application registered) with a <code>request_token</code>. </p>
<p>It is then up to the application to respond with the <code>request_token</code> to <code>POST</code> to <code>#{auth_url}/auth</code> with the <code>request_token</code>, their <code>client_id</code> and their <code>client_secret</code>, they will get an <code>auth_hash</code> with the user's credentials, uid, some profile information and more. The entire contents of the <code>auth_hash</code> are still up for debate, but will definitely contain the user's info.</p>
<p>When using the ruby language, they can use the Foundry's (soon-to-be) open-sourced <code>omniauth-att</code> library.</p>
<h2>Summary</h2>
<p><code>application -> 302 #{auth_url}/login</code></p>
<p><code>#{auth_url} 302 -> application/callback?request_token=code</code></p>
<p><code>application -> POST #{auth_url}/auth?code=code -> {"access_token":"token"}</code></p>
<p><code>application -> POST #{auth_url}/auth?code=code -> {"access_token":"token"}</code></p>
EOD
end end


get '/logout' do get '/logout' do
session[:authenticated] = false session[:authenticated] = false
redirect_to = ENV['BASE_DOMAIN'] || 'http://localhost:9393'
db[:access_token] = nil db[:access_token] = nil
redirect auth_url + "/logout?redirect_uri=#{CGI.escape(redirect_to)}" redirect auth_url + "/logout?redirect_uri=#{CGI.escape(base_domain)}"
end end


get '/env' do get '/env' do
Expand All @@ -96,13 +84,16 @@ def auth_url
(ENV['ATT_BASE_DOMAIN'] || 'https://auth.tfoundry.com') (ENV['ATT_BASE_DOMAIN'] || 'https://auth.tfoundry.com')
end end



def base_domain def base_domain
case ENV['RACK_ENV'] return 'http://localhost:5000'
when 'production' # return ENV['BASE_DOMAIN'] if ENV['BASE_DOMAIN']
"https://omniauth-att-example.herokuapp.com" # case ENV['RACK_ENV']
else # when 'production'
ENV['BASE_DOMAIN'] || 'http://localhost:9393' # "https://omniauth-att-example.herokuapp.com"
end # else
# 'http://localhost:9393'
# end
end end


end end
Expand Down Expand Up @@ -134,7 +125,7 @@ def base_domain
</html> </html>


@@index @@index
<% if db[:access_token] %> <% if db[:access_token] %>
<h4>Hurray! You already have an access token</h4> <h4>Hurray! You already have an access token</h4>
<%= db[:access_token] %> <%= db[:access_token] %>
Get your profile <a href='/protected'>here</a> Get your profile <a href='/protected'>here</a>
Expand All @@ -143,4 +134,26 @@ def base_domain
<a href='<%= base_domain %>/auth/facebook'>Login with facebook</a><br> <a href='<%= base_domain %>/auth/facebook'>Login with facebook</a><br>
<a href='<%= base_domain %>/auth/twitter'>Login with twitter</a><br> <a href='<%= base_domain %>/auth/twitter'>Login with twitter</a><br>
<a href='<%= base_domain %>/auth/att'>Login with att-foundry</a> <a href='<%= base_domain %>/auth/att'>Login with att-foundry</a>
<% end %> <% end %>

end

@@docs
<h2>Authentication docs page</h2>
<p>This is a sample application that shows how the authentication mechanism works.</p>
<p>It is incredibly simple and mimicks the OAuth2 flow. Firstly, the application must have
a <code>client_id</code> and a <code>client_secret</code>. When the application wants to get
an authenticated user, they can simply redirect the user with their <code>client_id</code> and a <code>redirect_uri</code> to
the foundry auth page at: #{auth_url}/login.
The foundry auth will take care of the login and redirecting the user back to the <code>redirect_uri</code> (provided it matches the one that the application registered) with a <code>request_token</code>. </p>

<p>It is then up to the application to respond with the <code>request_token</code> to <code>POST</code> to <code>#{auth_url}/auth</code> with the <code>request_token</code>, their <code>client_id</code> and their <code>client_secret</code>, they will get an <code>auth_hash</code> with the user's credentials, uid, some profile information and more. The entire contents of the <code>auth_hash</code> are still up for debate, but will definitely contain the user's info.</p>

<p>When using the ruby language, they can use the Foundry's (soon-to-be) open-sourced <code>omniauth-att</code> library.</p>

<h2>Summary</h2>

<p><code>application -> 302 #{auth_url}/login</code></p>
<p><code>#{auth_url} 302 -> application/callback?request_token=code</code></p>
<p><code>application -> POST #{auth_url}/auth?code=code -> {"access_token":"token"}</code></p>
<p><code>application -> POST #{auth_url}/auth?code=code -> {"access_token":"token"}</code></p>
6 changes: 1 addition & 5 deletions lib/omniauth/strategies/att.rb
Expand Up @@ -18,11 +18,7 @@ class Att < OmniAuth::Strategies::OAuth2
:token_url => '/oauth/access_token' :token_url => '/oauth/access_token'
} }


# These are called after authentication has succeeded. If # These are called after authentication has succeeded.
# possible, you should try to set the UID without making
# additional calls (if the user id is returned with the token
# or as a URI parameter). This may not be possible with all
# providers.
uid{ raw_info['uid'] } uid{ raw_info['uid'] }


info do info do
Expand Down

0 comments on commit 9caa5a1

Please sign in to comment.