Skip to content

Commit e467238

Browse files
committed
Use connection to start SSO auth flow
1 parent 95fc7f5 commit e467238

File tree

3 files changed

+11
-45
lines changed

3 files changed

+11
-45
lines changed

ruby-rails-sso-example/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ You'll need to create an [Organization](https://dashboard.workos.com/organizatio
3333

3434
Run `cp .env.example .env` and add your [API Key](https://dashboard.workos.com/api-keys) and [Client ID](https://dashboard.workos.com/configuration). The `workos` gem will read your API key from the ENV variable `WORKOS_API_KEY` and your Client ID from the ENV variable `WORKOS_CLIENT_ID`. You may also set the API key and Client ID yourself by adding `WorkOS.key = $YOUR_API_KEY` and `CLIENT_ID = $YOUR_CLIENT_ID` to `sessions_controller.rb`.
3535

36+
Additionally, you'll want to set the `CONNECTION_ID` in the `sessions_controller.rb` for the Connection you are testing.
37+
3638
## Run the application and sign in using SSO
3739

3840
Start the server:

ruby-rails-sso-example/app/controllers/users/sessions_controller.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ class Users::SessionsController < Devise::SessionsController
66
WorkOS.key = ENV['WORKOS_API_KEY']
77
CLIENT_ID = ENV['WORKOS_CLIENT_ID']
88

9+
# Set the Connection ID that you want to test
10+
CONNECTION_ID = 'conn_123'
11+
912
# GET /sso/new path to authenticate via WorkOS
1013
# You can also use connection or provider parameters
1114
# in place of the domain parameter
1215
# https://workos.com/docs/reference/sso/authorize/get
1316
def auth
1417
authorization_url = WorkOS::SSO.authorization_url(
15-
domain: params[:domain],
18+
connection: CONNECTION_ID,
1619
client_id: CLIENT_ID,
1720
redirect_uri: ENV['WORKOS_REDIRECT_URI'],
1821
)
Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,8 @@
11
<h2 class="text-center m-5">User Sign In</h2>
2-
<div class="container">
3-
<div class="row">
4-
<div class="col-md-6">
5-
<h4>Username and Password</h4>
6-
7-
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
8-
<div class="form-group">
9-
<%= f.label :email %><br />
10-
<%= f.email_field :email, autofocus: true, autocomplete: "email", class: 'form-control' %>
11-
</div>
12-
13-
<div class="form-group">
14-
<%= f.label :password %><br />
15-
<%= f.password_field :password, autocomplete: "current-password", class: 'form-control' %>
16-
</div>
17-
18-
<% if devise_mapping.rememberable? %>
19-
<div class="form-group">
20-
<%= f.check_box :remember_me, class: 'm-2' %>
21-
<%= f.label :remember_me %>
22-
</div>
23-
<% end %>
24-
25-
<div class="actions">
26-
<%= f.submit "Log in", class: 'btn btn-primary m-2' %>
27-
</div>
28-
<% end %>
29-
<hr>
30-
<%= render "users/shared/links" %>
2+
<div class="container text-center">
3+
<%= form_with url: sso_new_path, method: :get, local: true do |f| %>
4+
<div class="actions">
5+
<%= f.submit "Sign in with SSO", class: 'btn btn-primary m-2' %>
316
</div>
32-
<div class="col-md-6">
33-
<h4> Sign in with SSO </h4>
34-
35-
<%= form_with url: sso_new_path, method: :get, local: true do |f| %>
36-
<div class="form-group">
37-
<%= f.label :domain %><br />
38-
<%= f.text_field :domain, autofocus: true, autocomplete: "domain", class: 'form-control' %>
39-
</div>
40-
41-
<div class="actions">
42-
<%= f.submit "Sign in with SSO", class: 'btn btn-primary m-2' %>
43-
</div>
44-
<% end %>
45-
</div>
46-
</div>
7+
<% end %>
478
</div>

0 commit comments

Comments
 (0)