facebook-account-kit 1.0.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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/Gemfile +2 -0
- data/Makefile +11 -0
- data/README.md +67 -0
- data/facebook-account-kit.gemspec +23 -0
- data/lib/facebook/account_kit.rb +13 -0
- data/lib/facebook/account_kit/configuration.rb +11 -0
- data/lib/facebook/account_kit/http.rb +18 -0
- data/lib/facebook/account_kit/token_exchanger.rb +40 -0
- data/lib/facebook/account_kit/user_account.rb +40 -0
- data/lib/facebook/account_kit/version.rb +5 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c618c6a275539437ab7d5b00685728f3b8531f37
|
4
|
+
data.tar.gz: 9d3375403262f163715668784864c6867335ed43
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5bc14990749a7bbac420360a3ac13f4ff741efb2f8223e1d59be30a9e4b0f4ee49cfd387ba19e4fa027c3cf5d1b840167b4f2a4bb0fe01eb6861dd006f8fa274
|
7
|
+
data.tar.gz: 3d04cf22a4c1dad87b877e96fae0936fc41edcbbc4866d4e5882e4e0e5b491f78ce9bc5c7114f2763c6e4b9766b5d19913e87fee5685723f05526aa7330a8e8c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/Makefile
ADDED
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Facebook::AccountKit
|
2
|
+
|
3
|
+
This gem aims to facilitate the communication with Facebook's Account Kit. It implements the **server side** described in the [official docs](https://developers.facebook.com/docs/accountkit/web).
|
4
|
+
|
5
|
+
As of now it's assuming you have enabled `Require app secret` in your Account Kit page.
|
6
|
+
|
7
|
+
It only uses the core modules available as part of Ruby (so nothing too crazy in here 😬...)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'facebook-account-kit'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle install
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install facebook-account-kit
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Somewhere in your application (probably as part of a new `initializer`) you should add the following:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
Facebook::AccountKit.config do |c|
|
31
|
+
c.account_kit_version = 'v1.0' # or any other valid account kit api version
|
32
|
+
c.account_kit_app_secret = 'your account kit secret'
|
33
|
+
c.facebook_app_id = 'your facebook app id'
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
All of that information you can find as part of your Facebook app's `dashboard` and `account kit` pages.
|
38
|
+
|
39
|
+
The process of communicating with Facebook is divided into two steps.
|
40
|
+
|
41
|
+
During the first one you will use the `code` (AKA `authorization code`) that the client provided in exchange for an `access_token`:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
client_code = params[:code] # this depends on how your controller was implemented
|
45
|
+
token_exchanger = Facebook::AccountKit::TokenExchanger.new(client_code)
|
46
|
+
access_token = token_exchanger.fetch_access_token
|
47
|
+
```
|
48
|
+
|
49
|
+
...and with that access token you can request for the user information:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
user = Facebook::AccountKit::UserAccount.new(access_token)
|
53
|
+
user.fetch_user_info
|
54
|
+
```
|
55
|
+
|
56
|
+
## Development
|
57
|
+
|
58
|
+
There are different targets in the Makefile to help you to run the tests:
|
59
|
+
|
60
|
+
* Run all tests: `make test`
|
61
|
+
* Run unit tests: `make test.unit`
|
62
|
+
* Run integration tests: `make test.integration`
|
63
|
+
|
64
|
+
## Contributing
|
65
|
+
|
66
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nicholaspufal/facebook-account-kit
|
67
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'facebook/account_kit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'facebook-account-kit'
|
8
|
+
spec.version = Facebook::AccountKit::VERSION
|
9
|
+
spec.authors = ['Nicholas Pufal']
|
10
|
+
spec.email = ['niko.pufal@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = "A simple Ruby gem that makes it easier to work with Facebook's Account Kit"
|
13
|
+
spec.homepage = 'https://github.com/nicholaspufal/facebook-account-kit'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
20
|
+
spec.add_development_dependency 'rspec', '~> 3.4'
|
21
|
+
spec.add_development_dependency 'vcr', '~> 3.0'
|
22
|
+
spec.add_development_dependency 'webmock', '~> 2.1'
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'facebook/account_kit/configuration'
|
2
|
+
|
3
|
+
module Facebook
|
4
|
+
module AccountKit
|
5
|
+
def self.config
|
6
|
+
yield Configuration
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'facebook/account_kit/version'
|
12
|
+
require 'facebook/account_kit/token_exchanger'
|
13
|
+
require 'facebook/account_kit/user_account'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Facebook
|
5
|
+
module AccountKit
|
6
|
+
class InvalidRequest < StandardError; end
|
7
|
+
|
8
|
+
class HTTP
|
9
|
+
def self.get(url)
|
10
|
+
response = Net::HTTP.get_response url
|
11
|
+
parsed_response = JSON.parse(response.body)
|
12
|
+
raise InvalidRequest, parsed_response['error']['message'] if response.code != '200'
|
13
|
+
|
14
|
+
parsed_response
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative './http'
|
2
|
+
|
3
|
+
module Facebook
|
4
|
+
module AccountKit
|
5
|
+
class TokenExchanger
|
6
|
+
def initialize(authorization_code)
|
7
|
+
@authorization_code = authorization_code
|
8
|
+
end
|
9
|
+
|
10
|
+
def fetch_access_token
|
11
|
+
result = HTTP.get compose_url
|
12
|
+
result['access_token']
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def params
|
18
|
+
user_params = {
|
19
|
+
grant_type: 'authorization_code',
|
20
|
+
code: @authorization_code,
|
21
|
+
access_token: app_access_token
|
22
|
+
}
|
23
|
+
|
24
|
+
URI.encode_www_form(user_params)
|
25
|
+
end
|
26
|
+
|
27
|
+
def compose_url
|
28
|
+
URI(token_url + '?' + params)
|
29
|
+
end
|
30
|
+
|
31
|
+
def token_url
|
32
|
+
"https://graph.accountkit.com/#{Configuration.account_kit_version}/access_token"
|
33
|
+
end
|
34
|
+
|
35
|
+
def app_access_token
|
36
|
+
['AA', Configuration.facebook_app_id, Configuration.account_kit_app_secret].join('|')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative './http'
|
2
|
+
require 'openssl'
|
3
|
+
|
4
|
+
module Facebook
|
5
|
+
module AccountKit
|
6
|
+
class UserAccount
|
7
|
+
def initialize(access_token)
|
8
|
+
@access_token = access_token
|
9
|
+
end
|
10
|
+
|
11
|
+
def fetch_user_info
|
12
|
+
HTTP.get compose_url
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def params
|
18
|
+
token_params = {
|
19
|
+
access_token: @access_token,
|
20
|
+
appsecret_proof: secret_proof
|
21
|
+
}
|
22
|
+
|
23
|
+
URI.encode_www_form(token_params)
|
24
|
+
end
|
25
|
+
|
26
|
+
def secret_proof
|
27
|
+
digest = OpenSSL::Digest.new('sha256')
|
28
|
+
OpenSSL::HMAC.hexdigest(digest, Configuration.account_kit_app_secret, @access_token)
|
29
|
+
end
|
30
|
+
|
31
|
+
def compose_url
|
32
|
+
URI(me_url + '?' + params)
|
33
|
+
end
|
34
|
+
|
35
|
+
def me_url
|
36
|
+
"https://graph.accountkit.com/#{Configuration.account_kit_version}/me"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: facebook-account-kit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nicholas Pufal
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.4'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: vcr
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.1'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- niko.pufal@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- Gemfile
|
79
|
+
- Makefile
|
80
|
+
- README.md
|
81
|
+
- facebook-account-kit.gemspec
|
82
|
+
- lib/facebook/account_kit.rb
|
83
|
+
- lib/facebook/account_kit/configuration.rb
|
84
|
+
- lib/facebook/account_kit/http.rb
|
85
|
+
- lib/facebook/account_kit/token_exchanger.rb
|
86
|
+
- lib/facebook/account_kit/user_account.rb
|
87
|
+
- lib/facebook/account_kit/version.rb
|
88
|
+
homepage: https://github.com/nicholaspufal/facebook-account-kit
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.5.1
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: A simple Ruby gem that makes it easier to work with Facebook's Account Kit
|
112
|
+
test_files: []
|
113
|
+
has_rdoc:
|