Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Replaced the Twitter authentication by a Google (Apps) Mail authentic…

…ation
  • Loading branch information...
commit 199350b7f78612db42c3b980de06daae3e57379c 1 parent 39248c3
Nicolas Fouché authored

Showing 3 changed files with 37 additions and 19 deletions. Show diff stats Hide diff stats

  1. +14 0 README
  2. +17 16 app.rb
  3. +6 3 views/index.haml
14 README
... ... @@ -1,3 +1,17 @@
  1 +Fork notes:
  2 +
  3 +I updated the "twitter-oauth-sinatra" app to make it work with Google Mail and Google Apps Mail.
  4 +As a bonus, it gets the email address of the user, as we do on http://silentale.com. Quite useful if you want to use IMAP or SMTP with these tokens :)
  5 +
  6 +For your local tests, launch:
  7 +
  8 +CONSUMER_KEY=mydomain.com CONSUMER_SECRET=mysecret ruby app.rb
  9 +
  10 +Contact me at http://about.me/nfo
  11 +
  12 +
  13 +Original README:
  14 +
1 15 directions using heroku for hosting:
2 16
3 17 create twitter app at http://twitter.com/apps
33 app.rb
... ... @@ -1,8 +1,8 @@
1 1 require "rubygems"
2 2 require "sinatra"
  3 +require 'json'
3 4 require "oauth"
4 5 require "oauth/consumer"
5   -require 'grackle'
6 6 require 'haml'
7 7
8 8 enable :sessions
@@ -10,10 +10,15 @@
10 10 before do
11 11 session[:oauth] ||= {}
12 12
13   - consumer_key = ENV["consumer_key"]
14   - consumer_secret = ENV["consumer_secret"]
15   -
16   - @consumer ||= OAuth::Consumer.new(consumer_key, consumer_secret, :site => "http://twitter.com")
  13 + consumer_key = ENV["CONSUMER_KEY"] || ENV["consumer_key"]
  14 + consumer_secret = ENV["CONSUMER_SECRET"] || ENV["consumer_secret"]
  15 +
  16 + @consumer ||= OAuth::Consumer.new(consumer_key, consumer_secret,
  17 + :site => "https://www.google.com",
  18 + :request_token_path => '/accounts/OAuthGetRequestToken?scope=https://mail.google.com/%20https://www.googleapis.com/auth/userinfo%23email',
  19 + :access_token_path => '/accounts/OAuthGetAccessToken',
  20 + :authorize_path => '/accounts/OAuthAuthorizeToken'
  21 + )
17 22
18 23 if !session[:oauth][:request_token].nil? && !session[:oauth][:request_token_secret].nil?
19 24 @request_token = OAuth::RequestToken.new(@consumer, session[:oauth][:request_token], session[:oauth][:request_token_secret])
@@ -23,20 +28,16 @@
23 28 @access_token = OAuth::AccessToken.new(@consumer, session[:oauth][:access_token], session[:oauth][:access_token_secret])
24 29 end
25 30
26   - if @access_token
27   - @client = Grackle::Client.new(:auth => {
28   - :type => :oauth,
29   - :consumer_key => consumer_key,
30   - :consumer_secret => consumer_secret,
31   - :token => @access_token.token,
32   - :token_secret => @access_token.secret
33   - })
34   - end
35 31 end
36 32
37 33 get "/" do
38 34 if @access_token
39   - @statuses = @client.statuses.friends_timeline? :count => 100
  35 + response = @access_token.get('https://www.googleapis.com/userinfo/email?alt=json')
  36 + if response.is_a?(Net::HTTPSuccess)
  37 + @email = JSON.parse(response.body)['data']['email']
  38 + else
  39 + STDERR.puts "could not get email: #{response.inspect}"
  40 + end
40 41 haml :index
41 42 else
42 43 '<a href="/request">Sign On</a>'
@@ -44,7 +45,7 @@
44 45 end
45 46
46 47 get "/request" do
47   - @request_token = @consumer.get_request_token(:oauth_callback => "http://#{request.host}/auth")
  48 + @request_token = @consumer.get_request_token(:oauth_callback => "#{request.scheme}://#{request.host}:#{request.port}/auth")
48 49 session[:oauth][:request_token] = @request_token.token
49 50 session[:oauth][:request_token_secret] = @request_token.secret
50 51 redirect @request_token.authorize_url
9 views/index.haml
... ... @@ -1,5 +1,8 @@
1 1 %html
2 2 %body
3   - %ul
4   - - @statuses.each do |status|
5   - %li= status.text
  3 + %h3 Authorized email address
  4 + %p= @email || ":("
  5 + %h3 Token
  6 + %p= @access_token.token
  7 + %h3 Secret
  8 + %p= @access_token.secret

0 comments on commit 199350b

Please sign in to comment.
Something went wrong with that request. Please try again.