omniauth-facebook-access-token 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/README.markdown +45 -0
- data/lib/omniauth-facebook-access-token.rb +2 -0
- data/lib/omniauth-facebook-access-token/version.rb +5 -0
- data/lib/omniauth/strategies/facebook-access-token.rb +126 -0
- data/omniauth-facebook-access-token.gemspec +19 -0
- metadata +77 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/pkg
|
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# OmniAuth Facebook Access Token
|
2
|
+
|
3
|
+
Facebook Access Token Strategy for OmniAuth 1.0.
|
4
|
+
|
5
|
+
Supports client-side flow only. And fully compatible with [omniauth-facebook](https://github.com/mkdynamic/omniauth-facebook).
|
6
|
+
(Auth Hash is the same & etc')
|
7
|
+
|
8
|
+
Read the Facebook docs for more details: https://developers.facebook.com/docs/concepts/login/
|
9
|
+
|
10
|
+
## Installing
|
11
|
+
|
12
|
+
Add to your `Gemfile`:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'omniauth-facebook-access-token'
|
16
|
+
```
|
17
|
+
|
18
|
+
Then `bundle install`.
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
### Server-Side
|
23
|
+
`OmniAuth::Strategies::FacebookAccessToken` 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 :facebook_access_token, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET']
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
### Client-Side
|
34
|
+
|
35
|
+
Login via ajax GET/POST call to `/auth/facebook_access_token/callback` while providing `access_token` parameter.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
Copyright (c) 2012 by Dor Shahaf
|
40
|
+
|
41
|
+
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:
|
42
|
+
|
43
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
44
|
+
|
45
|
+
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,126 @@
|
|
1
|
+
require 'oauth2'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class FacebookAccessToken
|
6
|
+
include OmniAuth::Strategy
|
7
|
+
|
8
|
+
option :name, 'facebook_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://graph.facebook.com',
|
17
|
+
:token_url => '/oauth/access_token',
|
18
|
+
:ssl => { :version => "SSLv3" }
|
19
|
+
}
|
20
|
+
|
21
|
+
option :access_token_options, {
|
22
|
+
:header_format => 'OAuth %s',
|
23
|
+
:param_name => 'access_token'
|
24
|
+
}
|
25
|
+
|
26
|
+
attr_accessor :access_token
|
27
|
+
|
28
|
+
uid { raw_info['id'] }
|
29
|
+
|
30
|
+
info do
|
31
|
+
prune!({
|
32
|
+
'nickname' => raw_info['username'],
|
33
|
+
'email' => raw_info['email'],
|
34
|
+
'name' => raw_info['name'],
|
35
|
+
'first_name' => raw_info['first_name'],
|
36
|
+
'last_name' => raw_info['last_name'],
|
37
|
+
'image' => "#{options[:secure_image_url] ? 'https' : 'http'}://graph.facebook.com/#{uid}/picture?type=#{options[:image_size] || 'square'}",
|
38
|
+
'description' => raw_info['bio'],
|
39
|
+
'urls' => {
|
40
|
+
'Facebook' => raw_info['link'],
|
41
|
+
'Website' => raw_info['website']
|
42
|
+
},
|
43
|
+
'location' => (raw_info['location'] || {})['name'],
|
44
|
+
'verified' => raw_info['verified']
|
45
|
+
})
|
46
|
+
end
|
47
|
+
|
48
|
+
extra do
|
49
|
+
hash = {}
|
50
|
+
hash['raw_info'] = raw_info unless skip_info?
|
51
|
+
prune! hash
|
52
|
+
end
|
53
|
+
|
54
|
+
credentials do
|
55
|
+
hash = {'token' => access_token.token}
|
56
|
+
hash.merge!('refresh_token' => access_token.refresh_token) if access_token.expires? && access_token.refresh_token
|
57
|
+
hash.merge!('expires_at' => access_token.expires_at) if access_token.expires?
|
58
|
+
hash.merge!('expires' => access_token.expires?)
|
59
|
+
hash
|
60
|
+
end
|
61
|
+
|
62
|
+
def raw_info
|
63
|
+
@raw_info ||= access_token.get('/me').parsed || {}
|
64
|
+
end
|
65
|
+
|
66
|
+
def client
|
67
|
+
::OAuth2::Client.new(options.client_id, options.client_secret, options.client_options)
|
68
|
+
end
|
69
|
+
|
70
|
+
def request_phase
|
71
|
+
form = OmniAuth::Form.new(:title => "User Token", :url => callback_path)
|
72
|
+
form.text_field "Access Token", "access_token"
|
73
|
+
form.button "Sign In"
|
74
|
+
form.to_response
|
75
|
+
end
|
76
|
+
|
77
|
+
def callback_phase
|
78
|
+
if !request.params['access_token'] || request.params['access_token'].to_s.empty?
|
79
|
+
raise ArgumentError.new("No access token provided.")
|
80
|
+
end
|
81
|
+
|
82
|
+
self.access_token = build_access_token
|
83
|
+
self.access_token = self.access_token.refresh! if self.access_token.expired?
|
84
|
+
|
85
|
+
# Validate that the token belong to the application
|
86
|
+
app_raw = self.access_token.get('/app').parsed
|
87
|
+
if app_raw["id"] != options.client_id
|
88
|
+
raise ArgumentError.new("Access token doesn't belong to the client.")
|
89
|
+
end
|
90
|
+
|
91
|
+
# Instead of calling super, duplicate the functionlity, but change the provider to 'facebook'.
|
92
|
+
# This is done in order to preserve compatibilty with the regular facebook provider
|
93
|
+
hash = auth_hash
|
94
|
+
hash[:provider] = "facebook"
|
95
|
+
self.env['omniauth.auth'] = hash
|
96
|
+
call_app!
|
97
|
+
|
98
|
+
rescue ::OAuth2::Error
|
99
|
+
fail!(:invalid_credentials, e)
|
100
|
+
rescue ::MultiJson::DecodeError => e
|
101
|
+
fail!(:invalid_response, e)
|
102
|
+
rescue ::Timeout::Error, ::Errno::ETIMEDOUT => e
|
103
|
+
fail!(:timeout, e)
|
104
|
+
rescue ::SocketError => e
|
105
|
+
fail!(:failed_to_connect, e)
|
106
|
+
end
|
107
|
+
|
108
|
+
protected
|
109
|
+
|
110
|
+
def build_access_token
|
111
|
+
::OAuth2::AccessToken.from_hash(
|
112
|
+
client,
|
113
|
+
{"access_token" => request.params["access_token"]}.update(options.access_token_options)
|
114
|
+
)
|
115
|
+
end
|
116
|
+
|
117
|
+
def prune!(hash)
|
118
|
+
hash.delete_if do |_, value|
|
119
|
+
prune!(value) if value.is_a?(Hash)
|
120
|
+
value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/omniauth-facebook-access-token/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.add_dependency 'omniauth', '~> 1.0'
|
6
|
+
gem.add_dependency 'oauth2', '~> 0.8.0'
|
7
|
+
|
8
|
+
gem.authors = ["Dor Shahaf"]
|
9
|
+
gem.email = ["dor@shahaf.com"]
|
10
|
+
gem.description = %q{A Facebook using access-token strategy for OmniAuth. Can be used for client side Facebook login. }
|
11
|
+
gem.summary = %q{A Facebook using access-token strategy for OmniAuth.}
|
12
|
+
gem.homepage = "https://github.com/soapseller/omniauth-facebook-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-facebook-access-token"
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
gem.version = OmniAuth::FacebookAccessToken::VERSION
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-facebook-access-token
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dor Shahaf
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-22 00:00:00.000000000 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: omniauth
|
17
|
+
requirement: &7396580 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *7396580
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: oauth2
|
28
|
+
requirement: &7395980 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.8.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *7395980
|
37
|
+
description: ! 'A Facebook using access-token strategy for OmniAuth. Can be used for
|
38
|
+
client side Facebook login. '
|
39
|
+
email:
|
40
|
+
- dor@shahaf.com
|
41
|
+
executables: []
|
42
|
+
extensions: []
|
43
|
+
extra_rdoc_files: []
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- Gemfile
|
47
|
+
- README.markdown
|
48
|
+
- lib/omniauth-facebook-access-token.rb
|
49
|
+
- lib/omniauth-facebook-access-token/version.rb
|
50
|
+
- lib/omniauth/strategies/facebook-access-token.rb
|
51
|
+
- omniauth-facebook-access-token.gemspec
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: https://github.com/soapseller/omniauth-facebook-access-token
|
54
|
+
licenses: []
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.5.0
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: A Facebook using access-token strategy for OmniAuth.
|
77
|
+
test_files: []
|