jm81auth 0.1.4 → 0.1.5

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: 0c3c59397d88dbdf28d7e4d648d31add2778816b
4
- data.tar.gz: 5f9c327cf43476a2461cb2fbbd2143f60e1e6260
3
+ metadata.gz: ded0e7698676c978ab0a3118a7bbf259c11e4a26
4
+ data.tar.gz: d131e493284872c8b0d80c917f59cfef79f30412
5
5
  SHA512:
6
- metadata.gz: cd400241266aabd44738a03ebb93a7ca7d5b56e618bfad3ea44241acd8a8cf47a0cf621095a05c71c81f372f079a955757012d3fdce58094b12bb7a3dd51c890
7
- data.tar.gz: 3032d568c94dffae893cb2d17148f4ba5c7ff29a114ed4cc38b37dcc1637aea071bc5d98af16cc38ff20b4c631926766889672efacd87a5c556346694951b0a5
6
+ metadata.gz: 495587e42080bf7fa15a71ad5f65a47f43447dd7ae6dc31cd5b3717ce4887e48afec534dbe0b40058523aab1b0509fda5056325afd1b3b38a2c1ff00a23a19e1
7
+ data.tar.gz: 7838d9e94e26f48e74b1b6659b446c10a556727b4d592c0a89197d93330eb48f95f22b4b9db3493292997770d972bf45ebdb35413eabf08f20008b36be4c2e5c
@@ -15,15 +15,22 @@ module Jm81auth
15
15
  end
16
16
  end
17
17
 
18
- # Create AuthToken, setting user and last_used_at
18
+ # Create AuthToken, setting user and last_used_at, and optionally
19
+ # access_token from the Oauth provider.
19
20
  #
20
21
  # @return [AuthToken]
21
- def create_token
22
- if self.respond_to? :add_auth_token
23
- add_auth_token user: user, last_used_at: Time.now.utc
24
- else
25
- auth_tokens.create! user: user, last_used_at: Time.now.utc
22
+ def create_token access_token: nil
23
+ auth_token = ::AuthToken.new
24
+ auth_token.auth_method = self
25
+ auth_token.user = user
26
+ auth_token.last_used_at = Time.now.utc
27
+
28
+ if auth_token.respond_to? :access_token=
29
+ auth_token.access_token = access_token
26
30
  end
31
+
32
+ auth_token.save
33
+ auth_token
27
34
  end
28
35
 
29
36
  module ClassMethods
@@ -45,10 +45,7 @@ module Jm81auth
45
45
  method = ::AuthMethod.by_provider_data oauth.provider_data
46
46
 
47
47
  if !method
48
- user = find_by_email(oauth.email) || create(
49
- email: oauth.email.downcase,
50
- display_name: oauth.display_name
51
- )
48
+ user = find_by_email(oauth.email) || create_from_oauth(oauth)
52
49
 
53
50
  if user.respond_to? :add_auth_method
54
51
  method = user.add_auth_method oauth.provider_data
@@ -57,7 +54,20 @@ module Jm81auth
57
54
  end
58
55
  end
59
56
 
60
- method.create_token
57
+ method.create_token access_token: oauth.access_token
58
+ end
59
+
60
+ # Create User based on oauth data.
61
+ #
62
+ # @param oauth [OAuth::Base]
63
+ # OAuth login object, include #provider_data (Hash with provider_name
64
+ # and provider_id), #email and #display_name.
65
+ # @return [User]
66
+ def create_from_oauth oauth
67
+ create(
68
+ email: oauth.email.downcase,
69
+ display_name: oauth.display_name
70
+ )
61
71
  end
62
72
  end
63
73
  end
@@ -4,6 +4,8 @@
4
4
  module Jm81auth
5
5
  module OAuth
6
6
  class Base
7
+ attr_reader :access_token
8
+
7
9
  # Setup @params from params param (Har, har). Also, set @access_token,
8
10
  # either from params Hash, or by calling #get_access_token. @params is the
9
11
  # expected params needed by #get_access_token.
@@ -1,3 +1,3 @@
1
1
  module Jm81auth
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
3
3
  end
@@ -105,6 +105,7 @@ RSpec.describe User, type: :model do
105
105
  context 'existing AuthMethod' do
106
106
  before(:each) do
107
107
  expect(oauth).to_not receive(:email)
108
+ expect(oauth).to receive(:access_token)
108
109
 
109
110
  expect(oauth).to receive(:provider_data) do
110
111
  { provider_name: 'github', provider_id: 5 }
@@ -133,6 +134,8 @@ RSpec.describe User, type: :model do
133
134
 
134
135
  context 'no existing AuthMethod' do
135
136
  before(:each) do
137
+ expect(oauth).to receive(:access_token)
138
+
136
139
  expect(oauth).to receive(:provider_data).twice do
137
140
  { provider_name: 'github', provider_id: 10 }
138
141
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jm81auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Morgan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-31 00:00:00.000000000 Z
11
+ date: 2020-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient