forked from omniauth/omniauth-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds first working example with Twitter strategy.
- Loading branch information
Michael Bleigh
committed
Sep 28, 2011
0 parents
commit 4ca8741
Showing
8 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
*.gem | ||
*.rbc | ||
.bundle | ||
.config | ||
.yardoc | ||
Gemfile.lock | ||
InstalledFiles | ||
_yardoc | ||
coverage | ||
doc/ | ||
lib/bundler/man | ||
pkg | ||
rdoc | ||
spec/reports | ||
test/tmp | ||
test/version_tmp | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
source 'http://rubygems.org' | ||
|
||
# Specify your gem's dependencies in omniauth-contrib.gemspec | ||
gem 'omniauth', :git => 'git://github.com/intridea/omniauth.git' | ||
gem 'omniauth-oauth', :git => 'git://github.com/intridea/omniauth-oauth.git' | ||
|
||
gemspec | ||
|
||
group :example do | ||
gem 'sinatra' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env rake | ||
require "bundler/gem_tasks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'rubygems' | ||
require 'bundler' | ||
|
||
Bundler.setup :default, :development, :example | ||
require 'sinatra' | ||
require 'omniauth' | ||
require 'omniauth-contrib' | ||
|
||
use Rack::Session::Cookie | ||
|
||
use OmniAuth::Builder do | ||
provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET'] | ||
end | ||
|
||
get '/' do | ||
<<-HTML | ||
<ul> | ||
<li><a href='/auth/twitter'>Sign in with Twitter</a></li> | ||
</ul> | ||
HTML | ||
end | ||
|
||
get '/auth/:provider/callback' do | ||
content_type 'text/plain' | ||
request.env['omniauth.auth'].inspect | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require "omniauth-contrib/version" | ||
|
||
module OmniAuth | ||
module Strategies | ||
autoload :Twitter, 'omniauth/strategies/twitter' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module OmniAuth | ||
module Contrib | ||
VERSION = "0.0.1" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require 'omniauth-oauth' | ||
require 'multi_json' | ||
|
||
module OmniAuth | ||
module Strategies | ||
class Twitter < OmniAuth::Strategies::OAuth | ||
option :name, 'twitter' | ||
option :client_options, {:site => 'https://api.twitter.com'} | ||
option :sign_in, true | ||
option :force_sign_in, false | ||
|
||
def initialize(*args) | ||
super | ||
options.client_options[:authorize_path] = '/oauth/authenticate' if options.sign_in? | ||
options.authorize_params[:force_sign_in] = 'true' if options.force_sign_in? | ||
end | ||
|
||
def uid | ||
access_token.params[:user_id] | ||
end | ||
|
||
def info | ||
{ | ||
:nickname => raw_info['screen_name'], | ||
:name => raw_info['name'], | ||
:location => raw_info['location'], | ||
:image => raw_info['profile_image_url'], | ||
:description => raw_info['description'], | ||
:urls => { | ||
'Website' => raw_info['url'], | ||
'Twitter' => 'http://twitter.com/' + raw_info['screen_name'], | ||
} | ||
} | ||
end | ||
|
||
def raw_info | ||
@raw_info ||= MultiJson.decode(access_token.get('/1/account/verify_credentials.json').body) | ||
rescue ::Errno::ETIMEDOUT | ||
raise ::Timeout::Error | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- encoding: utf-8 -*- | ||
require File.expand_path('../lib/omniauth-contrib/version', __FILE__) | ||
|
||
Gem::Specification.new do |gem| | ||
gem.add_dependency 'omniauth', '~> 1.0.0.alpha' | ||
gem.add_dependency 'omniauth-oauth', '~> 1.0.0.alpha' | ||
gem.add_dependency 'multi_json' | ||
|
||
gem.authors = ["TODO: Write your name"] | ||
gem.email = ["michael@intridea.com"] | ||
gem.description = %q{TODO: Write a gem description} | ||
gem.summary = %q{TODO: Write a gem summary} | ||
gem.homepage = "" | ||
|
||
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
gem.files = `git ls-files`.split("\n") | ||
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
gem.name = "omniauth-contrib" | ||
gem.require_paths = ["lib"] | ||
gem.version = OmniAuth::Contrib::VERSION | ||
end |