Skip to content

Commit c749079

Browse files
authored
Add screen_hint to Ruby Gem + vcr 6 (#389)
* Add screen_hint to UserManagement As a solution to build "Sign-Up" paths in Rails applications, this adds the `screen_hint` to the UserManagement.authorization_url flow. This appears to be a valid api in NodeJS already (https://workos.com/docs/reference/authkit/authentication/get-authorization-url), this simply adds it to the Ruby Gem. Unit tests have been added as well. * Update VCR to resolve global_hook failure From research, this is a pretty well known issue in vcr 5 that has been resolved in vcr 6. Running bundle exec rspec still passes with this update. Resolves .rbenv/versions/3.1.4/lib/ruby/gems/3.1.0/gems/vcr-5.0.0/lib/vcr/library_hooks/webmock.rb:36:in `block in global_hook_disabled_requests': wrong number of arguments (given 1, expected 0) (ArgumentError).
1 parent 9e5a3b0 commit c749079

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

Gemfile.lock

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ GEM
3232
rainbow (3.1.1)
3333
regexp_parser (2.10.0)
3434
rexml (3.4.1)
35-
strscan
3635
rspec (3.9.0)
3736
rspec-core (~> 3.9.0)
3837
rspec-expectations (~> 3.9.0)
@@ -59,11 +58,11 @@ GEM
5958
rubocop-ast (1.37.0)
6059
parser (>= 3.3.1.0)
6160
ruby-progressbar (1.13.0)
62-
strscan (3.1.0)
6361
unicode-display_width (3.1.4)
6462
unicode-emoji (~> 4.0, >= 4.0.4)
6563
unicode-emoji (4.0.4)
66-
vcr (5.0.0)
64+
vcr (6.3.1)
65+
base64
6766
webmock (3.23.0)
6867
addressable (>= 2.8.0)
6968
crack (>= 0.3.2)
@@ -76,7 +75,7 @@ DEPENDENCIES
7675
bundler (>= 2.0.1)
7776
rspec (~> 3.9.0)
7877
rubocop (~> 1.71)
79-
vcr (~> 5.0.0)
78+
vcr (~> 6.0)
8079
webmock
8180
workos!
8281

lib/workos/user_management.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ def load_sealed_session(client_id:, session_data:, cookie_password:)
6969
# that is preserved and available to the client in the response.
7070
# @param [String] login_hint Can be used to pre-fill the username/email address
7171
# field of the IdP sign-in page for the user, if you know their username ahead of time.
72+
# @param [String] screen_hint Specify which AuthKit screen users should land on upon redirection
73+
# (Only applicable when provider is 'authkit').
7274
# @param [String] domain_hint Can be used to pre-fill the domain field when
7375
# initiating authentication with Microsoft OAuth, or with a GoogleSAML connection type.
7476
# @param [Array<String>] provider_scopes An array of additional OAuth scopes to request from the provider.
@@ -94,6 +96,7 @@ def authorization_url(
9496
client_id: nil,
9597
domain_hint: nil,
9698
login_hint: nil,
99+
screen_hint: nil,
97100
provider: nil,
98101
connection_id: nil,
99102
organization_id: nil,
@@ -114,6 +117,7 @@ def authorization_url(
114117
state: state,
115118
domain_hint: domain_hint,
116119
login_hint: login_hint,
120+
screen_hint: screen_hint,
117121
provider: provider,
118122
connection_id: connection_id,
119123
organization_id: organization_id,

spec/lib/workos/user_management_spec.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,41 @@
202202
end
203203
end
204204

205+
context 'with a screen hint' do
206+
let(:args) do
207+
{
208+
provider: 'authkit',
209+
screen_hint: 'sign_up',
210+
client_id: 'workos-proj-123',
211+
redirect_uri: 'foo.com/auth/callback',
212+
state: {
213+
next_page: '/dashboard/edit',
214+
}.to_s,
215+
}
216+
end
217+
it 'returns a valid URL' do
218+
authorization_url = described_class.authorization_url(**args)
219+
220+
expect(URI.parse(authorization_url)).to be_a URI
221+
end
222+
223+
it 'returns the expected hostname' do
224+
authorization_url = described_class.authorization_url(**args)
225+
226+
expect(URI.parse(authorization_url).host).to eq(WorkOS.config.api_hostname)
227+
end
228+
229+
it 'returns the expected query string' do
230+
authorization_url = described_class.authorization_url(**args)
231+
232+
expect(URI.parse(authorization_url).query).to eq(
233+
'client_id=workos-proj-123&redirect_uri=foo.com%2Fauth%2Fcallback' \
234+
'&response_type=code&state=%7B%3Anext_page%3D%3E%22%2Fdashboard%2F' \
235+
'edit%22%7D&screen_hint=sign_up&provider=authkit',
236+
)
237+
end
238+
end
239+
205240
context 'with neither connection_id, organization_id or provider' do
206241
let(:args) do
207242
{

workos.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
2727
spec.add_development_dependency 'bundler', '>= 2.0.1'
2828
spec.add_development_dependency 'rspec', '~> 3.9.0'
2929
spec.add_development_dependency 'rubocop', '~> 1.71'
30-
spec.add_development_dependency 'vcr', '~> 5.0.0'
30+
spec.add_development_dependency 'vcr', '~> 6.0'
3131
spec.add_development_dependency 'webmock'
3232

3333
spec.required_ruby_version = '>= 3.1'

0 commit comments

Comments
 (0)