account_kit 0.1.2 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 251a8969035dbfb38021a1eece9c1d3a98f2cf19
4
- data.tar.gz: cd2296c7f5aeac9da93f4524b8eb609994d340c0
3
+ metadata.gz: fd48f80314796341e8eec70fc0f1c61534eba109
4
+ data.tar.gz: f3c8cbeb479c9014b7c82d232f4516dacb4c34f7
5
5
  SHA512:
6
- metadata.gz: 96c3234a5b82c318f7f30f4f1dad91d45808bcb56b887c0d38b5b3aa44a2dee9af67b837334abea9b9c61889655cdaaf51dd736924b2046b02c6a094d6567f4e
7
- data.tar.gz: 3a5b2dcc476eb64b6c1f6b7f92313b1916b86dbb84a2f698c9124b958a018752d7a0f55ee97584d3bf347e9bcda754e7276fe4ebc03e3ff7b981604679b9c22e
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
- phone_code = response[:phone][:country_prefix]
51
- phone_number = response[:phone][:national_number]
57
+ phone_number = response[:phone][:number]
52
58
  ```
53
59
 
54
60
  ## Development
@@ -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
- module AccountKit
9
- extend self
10
-
11
- def configure
9
+ class AccountKit
10
+ def self.configure
12
11
  yield Config
13
12
  end
14
13
  end
@@ -1,9 +1,22 @@
1
- module AccountKit
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: 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', Config.app_id, Config.app_secret].join('|')
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
@@ -1,9 +1,10 @@
1
- module AccountKit
1
+ class AccountKit
2
2
  module Config
3
3
  extend self
4
4
 
5
5
  attr_accessor :app_id
6
6
  attr_accessor :app_secret
7
7
  attr_accessor :api_version
8
+ attr_accessor :require_app_secret
8
9
  end
9
10
  end
@@ -1,3 +1,3 @@
1
- module AccountKit
2
- VERSION = "0.1.2"
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.1.2
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-04-17 00:00:00.000000000 Z
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.5.1
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: