mirror of
https://github.com/nov/fb_graph2
synced 2023-03-27 23:22:15 -04:00
FbGraph2::Auth now works
This commit is contained in:
parent
d37667ba26
commit
c085f54530
2 changed files with 29 additions and 1 deletions
|
@ -1,13 +1,33 @@
|
|||
module FbGraph2
|
||||
class Auth < Rack::OAuth2::Client
|
||||
class Grant
|
||||
class FbExchangeToken < Rack::OAuth2::Client::Grant
|
||||
attr_required :fb_exchange_token
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(client_id, client_secret, options = {})
|
||||
super options.merge(
|
||||
identifier: client_id,
|
||||
secret: client_secret,
|
||||
host: URI.parse(FbGraph2.root_url).host,
|
||||
authorize_endpoint: '/oauth/authorize',
|
||||
authorization_endpoint: '/oauth/authorize',
|
||||
token_endpoint: '/oauth/access_token'
|
||||
)
|
||||
end
|
||||
|
||||
def fb_exchange_token=(access_token)
|
||||
@grant = Grant::FbExchangeToken.new(
|
||||
fb_exchange_token: access_token
|
||||
)
|
||||
end
|
||||
|
||||
def access_token!(options = {})
|
||||
super options.merge(
|
||||
client_auth_method: :body
|
||||
)
|
||||
rescue Rack::OAuth2::Client::Error => e
|
||||
raise Exception.detect_from_status(detect_from_status).new(e.message)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -22,4 +22,12 @@ describe FbGraph2::RequestFilter::Authenticator do
|
|||
request.header["Authorization"].should == ["Bearer #{token.access_token}"]
|
||||
end
|
||||
end
|
||||
|
||||
context 'when Rack::OAuth2::AccessToken::Legacy given' do
|
||||
let(:token) { Rack::OAuth2::AccessToken::Legacy.new access_token: 'token' }
|
||||
it do
|
||||
request_filter.filter_request(request)
|
||||
request.header["Authorization"].should == ["OAuth #{token.access_token}"]
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue