account_kit 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -3
- data/lib/account_kit.rb +3 -4
- data/lib/account_kit/base.rb +30 -10
- data/lib/account_kit/config.rb +2 -1
- data/lib/account_kit/version.rb +2 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd48f80314796341e8eec70fc0f1c61534eba109
|
4
|
+
data.tar.gz: f3c8cbeb479c9014b7c82d232f4516dacb4c34f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e0273d545b1c87c29910e19821173cf4c93b6dd039ba4e6e52ee00c751757c696e84b6a0ebce1e7b12ec993b85136413f0cdf3a2a9041d3c012953ef5d0a4dc
|
7
|
+
data.tar.gz: 3b798c56af915ee70c5343c73c2687c3babfb81ffb530d015b61b80fb6541f5cc6f23cab0d86f4124267a9a1a04d9fe69688d50b523fb0c58dd68d2bf7be0cb2
|
data/README.md
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
|
3
3
|
# AccountKit
|
4
4
|
A light-weight Ruby API client for [Facebook Account Kit](https://developers.facebook.com/docs/accountkit) with no dependency.
|
5
|
-
A demo of the Account Kit can be found [here](https://www.facebook.com/FacebookforDevelopers/videos/10153620979588553/).
|
5
|
+
A video demo of the Account Kit can be found [here](https://www.facebook.com/FacebookforDevelopers/videos/10153620979588553/).
|
6
|
+
You can find a demo app [here](https://github.com/vnnoder/account_kit_demo)
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
@@ -34,6 +35,12 @@ AccountKit.configure do |config|
|
|
34
35
|
end
|
35
36
|
```
|
36
37
|
|
38
|
+
AccountKit support App Secret Proof, if you turn on "Require App Secret", add the following config:
|
39
|
+
|
40
|
+
```
|
41
|
+
config.require_app_secret = true
|
42
|
+
```
|
43
|
+
|
37
44
|
### API
|
38
45
|
|
39
46
|
If you turn off Enable Client Access Token Flow and use [Authorization Code Flow](https://developers.facebook.com/docs/accountkit/accesstokens), you need to provide the authorization code after user authenticate with Account Kit in order to get an access token:
|
@@ -47,8 +54,7 @@ If you turn on Enable Client Access Token Flow, you should already have an acces
|
|
47
54
|
```
|
48
55
|
response = JSON.parse(AccountKit.me(access_token).body)
|
49
56
|
email = response[:email][:address]
|
50
|
-
|
51
|
-
phone_number = response[:phone][:national_number]
|
57
|
+
phone_number = response[:phone][:number]
|
52
58
|
```
|
53
59
|
|
54
60
|
## Development
|
data/lib/account_kit.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'json'
|
3
|
+
require 'openssl'
|
3
4
|
|
4
5
|
require 'account_kit/version'
|
5
6
|
require 'account_kit/base'
|
6
7
|
require 'account_kit/config'
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def configure
|
9
|
+
class AccountKit
|
10
|
+
def self.configure
|
12
11
|
yield Config
|
13
12
|
end
|
14
13
|
end
|
data/lib/account_kit/base.rb
CHANGED
@@ -1,9 +1,22 @@
|
|
1
|
-
|
2
|
-
extend self
|
1
|
+
class AccountKit
|
3
2
|
|
4
3
|
GRANT_TYPE = 'authorization_code'.freeze
|
5
4
|
DEFAULT_VERSION = 'v1.0'
|
6
5
|
|
6
|
+
class << self
|
7
|
+
# Support older versions
|
8
|
+
def method_missing(name, *args, &block)
|
9
|
+
new.send(name, *args, &block)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(options = {})
|
14
|
+
@app_id = options.fetch(:app_id, Config.app_id)
|
15
|
+
@app_secret = options.fetch(:app_secret, Config.app_secret)
|
16
|
+
@api_version = options.fetch(:api_version, Config.api_version || DEFAULT_VERSION)
|
17
|
+
@require_app_secret = options.fetch(:require_app_secret, Config.require_app_secret)
|
18
|
+
end
|
19
|
+
|
7
20
|
def access_token(code)
|
8
21
|
uri = build_access_token_uri(code)
|
9
22
|
send_payload(uri)
|
@@ -34,10 +47,21 @@ module AccountKit
|
|
34
47
|
|
35
48
|
def build_me_uri(access_token)
|
36
49
|
uri = URI(me_url)
|
37
|
-
uri.query = URI.encode_www_form(access_token
|
50
|
+
uri.query = URI.encode_www_form(me_params(access_token))
|
38
51
|
uri
|
39
52
|
end
|
40
53
|
|
54
|
+
def me_params(access_token)
|
55
|
+
params = { access_token: access_token }
|
56
|
+
params[:appsecret_proof] = appsecret_proof(access_token) if @require_app_secret
|
57
|
+
params
|
58
|
+
end
|
59
|
+
|
60
|
+
def appsecret_proof(access_token)
|
61
|
+
sha256 = OpenSSL::Digest::SHA256.new
|
62
|
+
OpenSSL::HMAC.hexdigest(sha256, @app_secret, access_token)
|
63
|
+
end
|
64
|
+
|
41
65
|
def access_token_params(code)
|
42
66
|
{
|
43
67
|
grant_type: GRANT_TYPE,
|
@@ -47,18 +71,14 @@ module AccountKit
|
|
47
71
|
end
|
48
72
|
|
49
73
|
def access_token_url
|
50
|
-
"https://graph.accountkit.com/#{api_version}/access_token"
|
74
|
+
"https://graph.accountkit.com/#{@api_version}/access_token"
|
51
75
|
end
|
52
76
|
|
53
77
|
def me_url
|
54
|
-
"https://graph.accountkit.com/#{api_version}/me"
|
78
|
+
"https://graph.accountkit.com/#{@api_version}/me"
|
55
79
|
end
|
56
80
|
|
57
81
|
def app_access_token
|
58
|
-
['AA',
|
59
|
-
end
|
60
|
-
|
61
|
-
def api_version
|
62
|
-
Config.api_version || DEFAULT_VERSION
|
82
|
+
['AA', @app_id, @app_secret].join('|')
|
63
83
|
end
|
64
84
|
end
|
data/lib/account_kit/config.rb
CHANGED
data/lib/account_kit/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.
|
1
|
+
class AccountKit
|
2
|
+
VERSION = "0.2.0"
|
3
3
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: account_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Duc Le
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2016-
|
14
|
+
date: 2016-10-05 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -99,8 +99,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
99
|
version: '0'
|
100
100
|
requirements: []
|
101
101
|
rubyforge_project:
|
102
|
-
rubygems_version: 2.
|
102
|
+
rubygems_version: 2.4.8
|
103
103
|
signing_key:
|
104
104
|
specification_version: 4
|
105
105
|
summary: A light-weight Ruby API client for Facebook Account Kit with no dependency.
|
106
106
|
test_files: []
|
107
|
+
has_rdoc:
|