mirror of
https://github.com/simi/omniauth-facebook.git
synced 2022-11-09 12:32:45 -05:00
use custom error class vs. regexp on string. use less terse fail names
This commit is contained in:
parent
093d550b27
commit
e14be7c6d6
2 changed files with 7 additions and 10 deletions
|
@ -7,6 +7,7 @@ module OmniAuth
|
|||
module Strategies
|
||||
class Facebook < OmniAuth::Strategies::OAuth2
|
||||
class NoAuthorizationCodeError < StandardError; end
|
||||
class UnknownSignatureAlgorithmError < NotImplementedError; end
|
||||
|
||||
DEFAULT_SCOPE = 'email'
|
||||
|
||||
|
@ -83,13 +84,9 @@ module OmniAuth
|
|||
def callback_phase
|
||||
super
|
||||
rescue NoAuthorizationCodeError => e
|
||||
fail!(:no_authz_code, e)
|
||||
rescue NotImplementedError => e
|
||||
if e.message =~ /unknown algorithm/i
|
||||
fail!(:algo_not_impl, e)
|
||||
else
|
||||
raise e
|
||||
end
|
||||
fail!(:no_authorization_code, e)
|
||||
rescue UnknownSignatureAlgorithmError => e
|
||||
fail!(:unknown_signature_algoruthm, e)
|
||||
end
|
||||
|
||||
def request_phase
|
||||
|
@ -213,7 +210,7 @@ module OmniAuth
|
|||
decoded_payload = MultiJson.decode(base64_decode_url(encoded_payload))
|
||||
|
||||
unless decoded_payload['algorithm'] == 'HMAC-SHA256'
|
||||
raise NotImplementedError, "unknown algorithm: #{decoded_payload['algorithm']}"
|
||||
raise UnknownSignatureAlgorithmError, "unknown algorithm: #{decoded_payload['algorithm']}"
|
||||
end
|
||||
|
||||
if valid_signature?(client.secret, decoded_hex_signature, encoded_payload)
|
||||
|
|
|
@ -426,7 +426,7 @@ module SignedRequestTests
|
|||
|
||||
test 'throws an error if the algorithm is unknown' do
|
||||
setup('UNKNOWN-ALGO')
|
||||
assert_equal "unknown algorithm: UNKNOWN-ALGO", assert_raises(NotImplementedError) { strategy.send(:signed_request) }.message
|
||||
assert_equal "unknown algorithm: UNKNOWN-ALGO", assert_raises(OmniAuth::Strategies::Facebook::UnknownSignatureAlgorithmError) { strategy.send(:signed_request) }.message
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -449,7 +449,7 @@ module SignedRequestTests
|
|||
|
||||
test 'throws an error if the algorithm is unknown' do
|
||||
setup('UNKNOWN-ALGO')
|
||||
assert_equal "unknown algorithm: UNKNOWN-ALGO", assert_raises(NotImplementedError) { strategy.send(:signed_request) }.message
|
||||
assert_equal "unknown algorithm: UNKNOWN-ALGO", assert_raises(OmniAuth::Strategies::Facebook::UnknownSignatureAlgorithmError) { strategy.send(:signed_request) }.message
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue