devise-multi_auth 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa514d0f2ebdb830ed0e7f2e7a391381063f5e8c
4
- data.tar.gz: 59b6f1d92a2792251e55eb425f594a9967a5842e
3
+ metadata.gz: 849b74ed9b30c38c32a2852238fc16be477bcfc1
4
+ data.tar.gz: acc769b30d431e3d3b1d4f4e4a455aa5811ecb09
5
5
  SHA512:
6
- metadata.gz: 86d0ae0cc9d7dbcbf6d233ebb43a21410952942f03c825b69e73e2640087d2af29c328bb828f807a34267bb4a79657986bfd091898c9117eb2c79b3f7b765b4c
7
- data.tar.gz: 6709a1f44f011a6cf46ff758ea8a0893623fc6dfa108bb1420daf5328d68585247ea8c3ba1111105db345edba106fa627d515cb2874e5294e04414c8cbb5c9a6
6
+ metadata.gz: 0360f20b3bc9ab5773364290744efc13754ac132be6f6667bc94cc875651e943b3f8d33b57282660c44de16cb27bf8a57887c5faccde944c81200a0a3a341b41
7
+ data.tar.gz: c55c51743249a8221140d13c24388b024e7f2d5ac60b7e6337e6c7eeecc4ea42a9a76568461530aab5f909f3ab565943338a45f59b0d326c59ad3bcf88322664
@@ -8,6 +8,8 @@ module Devise::MultiAuth
8
8
  client = options.fetch(:client)
9
9
  provider = options.fetch(:provider)
10
10
  where(provider: provider, uid: uid).first!.to_access_token(client: client)
11
+ rescue ActiveRecord::RecordNotFound
12
+ raise AccessTokenNotFound.new(provider: provider, uid: uid)
11
13
  end
12
14
 
13
15
  def self.find_user_by_provider_and_uid(provider, uid)
@@ -22,10 +24,18 @@ module Devise::MultiAuth
22
24
  where(provider: provider, uid: uid).includes(:user).first
23
25
  end
24
26
 
27
+ def verified?
28
+ access_token.present?
29
+ end
30
+
25
31
  def to_access_token(config = {})
26
32
  client = config.fetch(:client) { Devise::MultiAuth.oauth_client_for(provider) }
27
33
  tokenizer = config.fetch(:tokenizer) { ::OAuth2::AccessToken.method(:new) }
28
- tokenizer.call(client, access_token, refresh_token: refresh_token)
34
+ if verified?
35
+ tokenizer.call(client, access_token, refresh_token: refresh_token)
36
+ else
37
+ raise AccessTokenUnverified.new(provider: provider, uid: uid)
38
+ end
29
39
  end
30
40
  end
31
41
  end
@@ -1,4 +1,5 @@
1
1
  require "devise/multi_auth/engine"
2
+ require "devise/multi_auth/exceptions"
2
3
 
3
4
  module Devise::MultiAuth
4
5
  module_function
@@ -0,0 +1,22 @@
1
+ module Devise::MultiAuth
2
+ class AccessTokenError < RuntimeError
3
+ def initialize(options = {})
4
+ provider = options.fetch(:provider)
5
+ uid = options.fetch(:uid)
6
+ super("#{message_prefix} provider: #{provider.inspect}, uid: #{uid.inspect}.")
7
+ end
8
+ def message_prefix
9
+ "Unspecified access token error for"
10
+ end
11
+ end
12
+
13
+ class AccessTokenNotFound < AccessTokenError
14
+ def message_prefix
15
+ "Unable to find access token for"
16
+ end
17
+ end
18
+
19
+ class AccessTokenUnverified < AccessTokenError
20
+ "Possible access token found but unverified for"
21
+ end
22
+ end
@@ -1,5 +1,5 @@
1
1
  module Devise
2
2
  module MultiAuth
3
- VERSION = "0.0.5"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise-multi_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jeremy.n.friesen@gmail.com
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-05 00:00:00.000000000 Z
11
+ date: 2014-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -148,6 +148,7 @@ files:
148
148
  - app/services/devise/multi_auth/capture_successful_external_authentication.rb
149
149
  - db/migrate/20140204141526_create_authentications.rb
150
150
  - lib/devise/multi_auth/engine.rb
151
+ - lib/devise/multi_auth/exceptions.rb
151
152
  - lib/devise/multi_auth/version.rb
152
153
  - lib/devise/multi_auth.rb
153
154
  - lib/devise-multi_auth.rb