Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…ation
  • Loading branch information...
commit 199350b7f78612db42c3b980de06daae3e57379c 1 parent 39248c3
Nicolas Fouché authored
Showing with 37 additions and 19 deletions.
  1. +14 −0 README
  2. +17 −16 app.rb
  3. +6 −3 views/index.haml
View
14 README
@@ -1,3 +1,17 @@
+Fork notes:
+
+I updated the "twitter-oauth-sinatra" app to make it work with Google Mail and Google Apps Mail.
+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 :)
+
+For your local tests, launch:
+
+CONSUMER_KEY=mydomain.com CONSUMER_SECRET=mysecret ruby app.rb
+
+Contact me at http://about.me/nfo
+
+
+Original README:
+
directions using heroku for hosting:
create twitter app at http://twitter.com/apps
View
33 app.rb
@@ -1,8 +1,8 @@
require "rubygems"
require "sinatra"
+require 'json'
require "oauth"
require "oauth/consumer"
-require 'grackle'
require 'haml'
enable :sessions
@@ -10,10 +10,15 @@
before do
session[:oauth] ||= {}
- consumer_key = ENV["consumer_key"]
- consumer_secret = ENV["consumer_secret"]
-
- @consumer ||= OAuth::Consumer.new(consumer_key, consumer_secret, :site => "http://twitter.com")
+ consumer_key = ENV["CONSUMER_KEY"] || ENV["consumer_key"]
+ consumer_secret = ENV["CONSUMER_SECRET"] || ENV["consumer_secret"]
+
+ @consumer ||= OAuth::Consumer.new(consumer_key, consumer_secret,
+ :site => "https://www.google.com",
+ :request_token_path => '/accounts/OAuthGetRequestToken?scope=https://mail.google.com/%20https://www.googleapis.com/auth/userinfo%23email',
+ :access_token_path => '/accounts/OAuthGetAccessToken',
+ :authorize_path => '/accounts/OAuthAuthorizeToken'
+ )
if !session[:oauth][:request_token].nil? && !session[:oauth][:request_token_secret].nil?
@request_token = OAuth::RequestToken.new(@consumer, session[:oauth][:request_token], session[:oauth][:request_token_secret])
@@ -23,20 +28,16 @@
@access_token = OAuth::AccessToken.new(@consumer, session[:oauth][:access_token], session[:oauth][:access_token_secret])
end
- if @access_token
- @client = Grackle::Client.new(:auth => {
- :type => :oauth,
- :consumer_key => consumer_key,
- :consumer_secret => consumer_secret,
- :token => @access_token.token,
- :token_secret => @access_token.secret
- })
- end
end
get "/" do
if @access_token
- @statuses = @client.statuses.friends_timeline? :count => 100
+ response = @access_token.get('https://www.googleapis.com/userinfo/email?alt=json')
+ if response.is_a?(Net::HTTPSuccess)
+ @email = JSON.parse(response.body)['data']['email']
+ else
+ STDERR.puts "could not get email: #{response.inspect}"
+ end
haml :index
else
'<a href="/request">Sign On</a>'
@@ -44,7 +45,7 @@
end
get "/request" do
- @request_token = @consumer.get_request_token(:oauth_callback => "http://#{request.host}/auth")
+ @request_token = @consumer.get_request_token(:oauth_callback => "#{request.scheme}://#{request.host}:#{request.port}/auth")
session[:oauth][:request_token] = @request_token.token
session[:oauth][:request_token_secret] = @request_token.secret
redirect @request_token.authorize_url
View
9 views/index.haml
@@ -1,5 +1,8 @@
%html
%body
- %ul
- - @statuses.each do |status|
- %li= status.text
+ %h3 Authorized email address
+ %p= @email || ":("
+ %h3 Token
+ %p= @access_token.token
+ %h3 Secret
+ %p= @access_token.secret
Please sign in to comment.
Something went wrong with that request. Please try again.