omniauth-twitter-access-token 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/Gemfile +4 -0
- data/README.markdown +67 -0
- data/lib/omniauth-twitter-access-token.rb +2 -0
- data/lib/omniauth-twitter-access-token/version.rb +5 -0
- data/lib/omniauth/strategies/twitter-access-token.rb +138 -0
- data/omniauth-twitter-access-token.gemspec +19 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d0f78f45168efa9d34e7b5e0d01542a398221a6e
|
4
|
+
data.tar.gz: 6e90eea0c6bfb8addee3aec1883861ec5ca99021
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e69b95ef5bb4f470f91e7f0390ad6d1bf512d9da1b1435ee05ef3dcf0c4ee4ea4099dadf04a07f577c6164795efb0a1b2c02b7b51e7e4b7df42ff174a2f74802
|
7
|
+
data.tar.gz: b0a0f75b92527954d3c869b940d9913cee244d4b09460bf92be63b11c6e019f7dea00e8d114dce0e2edcd307bda376057d0dafe3496cac1e6f046a744205990f
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# OmniAuth Twitter Access Token
|
2
|
+
|
3
|
+
Twitter Access Token Strategy for OmniAuth 1.0.
|
4
|
+
|
5
|
+
Supports client-side flow only. And fully compatible with [omniauth-twitter](https://github.com/arunagw/omniauth-twitter).
|
6
|
+
(Auth Hash is the same & etc')
|
7
|
+
|
8
|
+
Mostly shamelessly copied from [omniauth-facebook-access-token](https://github.com/SoapSeller/omniauth-facebook-access-token)
|
9
|
+
|
10
|
+
## Installing
|
11
|
+
|
12
|
+
Add to your `Gemfile`:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'omniauth-twitter-access-token'
|
16
|
+
```
|
17
|
+
|
18
|
+
Then `bundle install`.
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
### Server-Side
|
23
|
+
`OmniAuth::Strategies::TwitterAccessToken` is simply a Rack middleware. Read the OmniAuth 1.0 docs for detailed instructions: https://github.com/intridea/omniauth.
|
24
|
+
|
25
|
+
Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
29
|
+
provider :twitter_access_token, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET']
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
### Client-Side
|
34
|
+
|
35
|
+
Login via ajax GET/POST call to `/auth/twitter_access_token/callback` while providing `token` & `token-secret` parameter.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
omniauth-twitter-access-token is licensed under MIT license.
|
40
|
+
|
41
|
+
Copyright (C) 2012-2013 Tom de Grunt <tom@degrunt.nl>
|
42
|
+
|
43
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
44
|
+
this software and associated documentation files (the "Software"), to deal in
|
45
|
+
the Software without restriction, including without limitation the rights to
|
46
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
47
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
48
|
+
so, subject to the following conditions:
|
49
|
+
|
50
|
+
The above copyright notice and this permission notice shall be included in all
|
51
|
+
copies or substantial portions of the Software.
|
52
|
+
|
53
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
54
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
55
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
56
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
57
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
58
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
59
|
+
SOFTWARE.
|
60
|
+
|
61
|
+
Copyright (c) 2012 by Dor Shahaf
|
62
|
+
|
63
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
64
|
+
|
65
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
66
|
+
|
67
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'oauth'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class TwitterAccessToken
|
6
|
+
include OmniAuth::Strategy
|
7
|
+
|
8
|
+
option :name, 'twitter_access_token'
|
9
|
+
|
10
|
+
args [:client_id, :client_secret]
|
11
|
+
|
12
|
+
option :client_id, nil
|
13
|
+
option :client_secret, nil
|
14
|
+
|
15
|
+
option :client_options, {
|
16
|
+
:site => 'https://api.twitter.com',
|
17
|
+
:authorize_path => '/oauth/authenticate',
|
18
|
+
:request_token_path => '/oauth/request_token',
|
19
|
+
:access_token_path => '/oauth/access_token',
|
20
|
+
:ssl => { :version => "SSLv3" }
|
21
|
+
}
|
22
|
+
|
23
|
+
option :access_token_options, {
|
24
|
+
:header_format => 'OAuth %s',
|
25
|
+
:param_name => 'access_token'
|
26
|
+
}
|
27
|
+
|
28
|
+
attr_accessor :access_token
|
29
|
+
|
30
|
+
uid { raw_info['id'] }
|
31
|
+
|
32
|
+
info do
|
33
|
+
{
|
34
|
+
:nickname => raw_info['screen_name'],
|
35
|
+
:name => raw_info['name'],
|
36
|
+
:location => raw_info['location'],
|
37
|
+
:image => image_url(options),
|
38
|
+
:description => raw_info['description'],
|
39
|
+
:urls => {
|
40
|
+
'Website' => raw_info['url'],
|
41
|
+
'Twitter' => "https://twitter.com/#{raw_info['screen_name']}",
|
42
|
+
}
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
extra do
|
47
|
+
{ :raw_info => raw_info }
|
48
|
+
end
|
49
|
+
|
50
|
+
credentials do
|
51
|
+
hash = {'token' => access_token.token}
|
52
|
+
hash
|
53
|
+
end
|
54
|
+
|
55
|
+
def raw_info
|
56
|
+
@raw_info ||= JSON.parse(access_token.get('/1.1/account/verify_credentials.json?include_entities=false&skip_status=true').body) || {}
|
57
|
+
end
|
58
|
+
|
59
|
+
def client
|
60
|
+
::OAuth::Consumer.new(options.client_id, options.client_secret, deep_symbolize(options.client_options))
|
61
|
+
end
|
62
|
+
|
63
|
+
def request_phase
|
64
|
+
form = OmniAuth::Form.new(:title => "User Token", :url => callback_path)
|
65
|
+
form.text_field "Token", "token"
|
66
|
+
form.text_field "Token Secret", "token_secret"
|
67
|
+
form.button "Sign In"
|
68
|
+
form.to_response
|
69
|
+
end
|
70
|
+
|
71
|
+
def callback_phase
|
72
|
+
if !request.params['token'] || request.params['token'].to_s.empty?
|
73
|
+
raise ArgumentError.new("No access token provided.")
|
74
|
+
end
|
75
|
+
if !request.params['token_secret'] || request.params['token_secret'].to_s.empty?
|
76
|
+
raise ArgumentError.new("No token secret provided.")
|
77
|
+
end
|
78
|
+
|
79
|
+
self.access_token = build_access_token
|
80
|
+
#self.access_token = self.access_token.refresh! if self.access_token.expired?
|
81
|
+
|
82
|
+
# Validate that the token belong to the application
|
83
|
+
# app_raw = self.access_token.get('/app').parsed
|
84
|
+
# if app_raw["id"] != options.client_id
|
85
|
+
# raise ArgumentError.new("Access token doesn't belong to the client.")
|
86
|
+
# end
|
87
|
+
|
88
|
+
# Instead of calling super, duplicate the functionlity, but change the provider to 'facebook'.
|
89
|
+
# This is done in order to preserve compatibilty with the regular facebook provider
|
90
|
+
hash = auth_hash
|
91
|
+
hash[:provider] = "twitter"
|
92
|
+
self.env['omniauth.auth'] = hash
|
93
|
+
call_app!
|
94
|
+
|
95
|
+
rescue ::OAuth::Error => e
|
96
|
+
fail!(:invalid_credentials, e)
|
97
|
+
rescue ::MultiJson::DecodeError => e
|
98
|
+
fail!(:invalid_response, e)
|
99
|
+
rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
|
100
|
+
fail!(:timeout, e)
|
101
|
+
rescue ::SocketError => e
|
102
|
+
fail!(:failed_to_connect, e)
|
103
|
+
end
|
104
|
+
|
105
|
+
protected
|
106
|
+
|
107
|
+
def deep_symbolize(hash)
|
108
|
+
hash.inject({}) do |h, (k,v)|
|
109
|
+
h[k.to_sym] = v.is_a?(Hash) ? deep_symbolize(v) : v
|
110
|
+
h
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def build_access_token
|
115
|
+
::OAuth::AccessToken.new(
|
116
|
+
client,
|
117
|
+
request.params["token"],
|
118
|
+
request.params["token_secret"]
|
119
|
+
)
|
120
|
+
end
|
121
|
+
|
122
|
+
def image_url(options)
|
123
|
+
original_url = options[:secure_image_url] ? raw_info['profile_image_url_https'] : raw_info['profile_image_url']
|
124
|
+
case options[:image_size]
|
125
|
+
when 'mini'
|
126
|
+
original_url.sub('normal', 'mini')
|
127
|
+
when 'bigger'
|
128
|
+
original_url.sub('normal', 'bigger')
|
129
|
+
when 'original'
|
130
|
+
original_url.sub('_normal', '')
|
131
|
+
else
|
132
|
+
original_url
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/omniauth-twitter-access-token/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.add_dependency 'omniauth', '~> 1.0'
|
6
|
+
gem.add_dependency 'oauth', '~> 0.4.7'
|
7
|
+
|
8
|
+
gem.authors = ["Tom de Grunt"]
|
9
|
+
gem.email = ["tom@degrunt.nl"]
|
10
|
+
gem.description = %q{A Twitter strategy using token/token-secret for OmniAuth. Can be used for client side Twitter login. }
|
11
|
+
gem.summary = %q{A Twitter strategy using token/token-secret for OmniAuth.}
|
12
|
+
gem.homepage = "https://github.com/tdegrunt/omniauth-twitter-access-token"
|
13
|
+
|
14
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
|
+
gem.files = `git ls-files`.split("\n")
|
16
|
+
gem.name = "omniauth-twitter-access-token"
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
gem.version = OmniAuth::TwitterAccessToken::VERSION
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-twitter-access-token
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tom de Grunt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: omniauth
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: oauth
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.4.7
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.4.7
|
41
|
+
description: 'A Twitter strategy using token/token-secret for OmniAuth. Can be used
|
42
|
+
for client side Twitter login. '
|
43
|
+
email:
|
44
|
+
- tom@degrunt.nl
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- README.markdown
|
52
|
+
- lib/omniauth-twitter-access-token.rb
|
53
|
+
- lib/omniauth-twitter-access-token/version.rb
|
54
|
+
- lib/omniauth/strategies/twitter-access-token.rb
|
55
|
+
- omniauth-twitter-access-token.gemspec
|
56
|
+
homepage: https://github.com/tdegrunt/omniauth-twitter-access-token
|
57
|
+
licenses: []
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.2.2
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: A Twitter strategy using token/token-secret for OmniAuth.
|
79
|
+
test_files: []
|