Class: FbGraph2::Auth
- Inherits:
-
Rack::OAuth2::Client
- Object
- Rack::OAuth2::Client
- FbGraph2::Auth
show all
- Defined in:
- lib/fb_graph2/auth.rb,
lib/fb_graph2/auth/signed_request.rb
Defined Under Namespace
Classes: Grant, SignedRequest
Instance Method Summary
collapse
Constructor Details
#initialize(client_id, client_secret, options = {}) ⇒ Auth
Returns a new instance of Auth.
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/fb_graph2/auth.rb', line 11
def initialize(client_id, client_secret, options = {})
super options.merge(
identifier: client_id,
secret: client_secret,
host: URI.parse(FbGraph2.root_url).host,
authorization_endpoint: File.join('/', FbGraph2.api_version, '/oauth/authorize'),
token_endpoint: File.join('/', FbGraph2.api_version, '/oauth/access_token'),
client_code_endpoint: File.join('/', FbGraph2.api_version, '/oauth/client_code')
)
end
|
Instance Method Details
#access_token!(options = {}) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/fb_graph2/auth.rb', line 28
def access_token!(options = {})
super options.merge(
client_auth_method: :body
)
rescue Rack::OAuth2::Client::Error => e
raise Exception.detect(e.status, e.response)
end
|
#client_code!(access_token, options = {}) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/fb_graph2/auth.rb', line 36
def client_code!(access_token, options = {})
params = {
access_token: access_token,
client_id: identifier,
client_secret: secret,
redirect_uri: redirect_uri
}.merge(options)
response = Rack::OAuth2.http_client.post(
absolute_uri_for(client_code_endpoint),
params
)
response_json = JSON.parse(response.body).with_indifferent_access
case response.status
when 200..201
response_json
else
raise Exception.detect(response.status, response_json)
end
end
|
#debug_token!(input_token) ⇒ Object
56
57
58
59
60
61
62
|
# File 'lib/fb_graph2/auth.rb', line 56
def debug_token!(input_token)
token_metadata = TokenMetadata.new
token_metadata.authenticate access_token!
token_metadata.fetch(
input_token: input_token.to_s
)
end
|
#fb_exchange_token=(access_token) ⇒ Object
22
23
24
25
26
|
# File 'lib/fb_graph2/auth.rb', line 22
def fb_exchange_token=(access_token)
@grant = Grant::FbExchangeToken.new(
fb_exchange_token: access_token
)
end
|
#from_cookie(cookie) ⇒ Object
64
65
66
67
68
69
70
71
72
|
# File 'lib/fb_graph2/auth.rb', line 64
def from_cookie(cookie)
token = case cookie
when String
cookie
else
cookie.delete "fbsr_#{identifier}"
end
from_signed_request token
end
|
#from_signed_request(token) ⇒ Object
74
75
76
|
# File 'lib/fb_graph2/auth.rb', line 74
def from_signed_request(token)
SignedRequest.new(token).verify! self
end
|