yt-auth 1.0.0 → 1.1.0

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
  SHA256:
3
- metadata.gz: cdfefa6ede46c8b10e59770092ed43beeccf56a54211f5d97dcb8e9355ea2966
4
- data.tar.gz: 1e1c3d106efa74d854155f39076f0fdfe19b1c9fa2cbfdbd9b46fd13a6aab9ba
3
+ metadata.gz: 05a1a75f5f8f810adcf491d297677e947d2e5cd78107cfbd313e1188a9db17c0
4
+ data.tar.gz: b67125a4109041568d7e9934fbc47f05b468c131c5917efc1e9cca71d0ee90b1
5
5
  SHA512:
6
- metadata.gz: a61619e2f28f1ca1926375147bf05cd17a6b45676a64757b96281dc88927892db4c9e5ccad2c57f06eb3041c78047c19c0094073a57a6e8b4c617c6d53f01bb6
7
- data.tar.gz: '05249f451e92f0b2d389ce5bb9f28a354ba79697b625a2e2a28579dd2c7ca26d1ffffbd86be6ba555d7cb634c37af61c7cdf46cd0d4c3257282be6e42b595b4f'
6
+ metadata.gz: 81a37ada6ca52b871e50cb87f1d0314c49f4b6464072f5a26875d44aa96f6f30ac54a1474c8921d99b26fbf3711de46d83faf5f3604acf157875b545cd12361d
7
+ data.tar.gz: b7f95d81006bc85665587abbbb5dbf8f75cb68f0aa221e85556d6aa31764f414fb328643edf319a79ff00e9f1e3d9f21361be35c5b237f325bf4693d9e55e4b2
data/CHANGELOG.md CHANGED
@@ -6,6 +6,14 @@ For more information about changelogs, check
6
6
  [Keep a Changelog](http://keepachangelog.com) and
7
7
  [Vandamme](http://tech-angels.github.io/vandamme).
8
8
 
9
+ ## 1.1.0 - 2024-12-10
10
+
11
+ * [FEATURE] Support mocking
12
+
13
+ - Use `Yt.configuration.mock_auth_error` to mock an error response
14
+ - Use `Yt.configuration.mock_auth_email` to mock authenticating as an email
15
+ - If the value of `mock_auth_email` is `invalid-email`, raise a Yt::HTTPError
16
+
9
17
  ## 1.0.0 - 2024-11-26
10
18
 
11
19
  Released major version. No breaking changes.
@@ -2,6 +2,6 @@ module Yt
2
2
  class Auth
3
3
  # @return [String] the SemVer-compatible gem version.
4
4
  # @see http://semver.org
5
- VERSION = '1.0.0'
5
+ VERSION = '1.1.0'
6
6
  end
7
7
  end
data/lib/yt/auth.rb CHANGED
@@ -33,10 +33,16 @@ module Yt
33
33
  # @option options [Array<String>] :scopes The list of scopes that users
34
34
  # are requested to authorize.
35
35
  def self.url_for(options = {})
36
- host = 'accounts.google.com'
37
- path = '/o/oauth2/auth'
38
- query = URI.encode_www_form url_params(options)
39
- URI::HTTPS.build(host: host, path: path, query: query).to_s
36
+ if Yt.configuration.mock_auth_error
37
+ options[:redirect_uri] + '?error=' + Yt.configuration.mock_auth_error
38
+ elsif Yt.configuration.mock_auth_email
39
+ options[:redirect_uri] + '?code=mock-email'
40
+ else
41
+ host = 'accounts.google.com'
42
+ path = '/o/oauth2/auth'
43
+ query = URI.encode_www_form url_params(options)
44
+ URI::HTTPS.build(host: host, path: path, query: query).to_s
45
+ end
40
46
  end
41
47
 
42
48
  # @param [Hash] options the options to initialize an instance of Yt::Auth.
@@ -57,7 +63,15 @@ module Yt
57
63
 
58
64
  # @return [String] the email of an authenticated Google account.
59
65
  def email
60
- profile['email']
66
+ if Yt.configuration.mock_auth_email
67
+ if Yt.configuration.mock_auth_email.eql? 'invalid-email'
68
+ raise Yt::HTTPError, 'Malformed auth code'
69
+ else
70
+ Yt.configuration.mock_auth_email
71
+ end
72
+ else
73
+ profile['email']
74
+ end
61
75
  end
62
76
 
63
77
  # @return [String] the access token of an authenticated Google account.
@@ -113,7 +127,7 @@ module Yt
113
127
  params[:method] = :post
114
128
  params[:request_format] = :form
115
129
  params[:body] = @tokens_body
116
- params[:error_message] = ->(body) { error_message_for body }
130
+ params[:error_message] = ->(code) { error_message_for code }
117
131
  end
118
132
  end
119
133
 
@@ -125,7 +139,7 @@ module Yt
125
139
  end
126
140
  end
127
141
 
128
- def error_message_for(body)
142
+ def error_message_for(code)
129
143
  key = @tokens_body[:grant_type].to_s.tr '_', ' '
130
144
  JSON(body)['error_description'] || "Invalid #{key}."
131
145
  end
data/yt-auth.gemspec CHANGED
@@ -24,11 +24,10 @@ Gem::Specification.new do |spec|
24
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ['lib']
26
26
 
27
- spec.add_dependency 'yt-support', '>= 0.1.3'
27
+ spec.add_dependency 'yt-support', '~> 1.0'
28
28
  spec.add_dependency 'jwt', '>= 1.5.6'
29
29
 
30
30
  spec.add_development_dependency 'bundler'
31
- spec.add_development_dependency 'debug'
32
31
  spec.add_development_dependency 'rspec'#, '~> 3.5'
33
32
  spec.add_development_dependency 'rake'#, '~> 12.0'
34
33
  spec.add_development_dependency 'coveralls'#, '~> 0.8.20'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yt-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Baccigalupo
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-11-27 00:00:00.000000000 Z
12
+ date: 2024-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yt-support
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ">="
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 0.1.3
20
+ version: '1.0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">="
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 0.1.3
27
+ version: '1.0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: jwt
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -53,20 +53,6 @@ dependencies:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
- - !ruby/object:Gem::Dependency
57
- name: debug
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: '0'
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
56
  - !ruby/object:Gem::Dependency
71
57
  name: rspec
72
58
  requirement: !ruby/object:Gem::Requirement
@@ -165,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
151
  - !ruby/object:Gem::Version
166
152
  version: '0'
167
153
  requirements: []
168
- rubygems_version: 3.5.22
154
+ rubygems_version: 3.5.23
169
155
  signing_key:
170
156
  specification_version: 4
171
157
  summary: Google Authentication Ruby client