Module: WorkOS::SSO
Overview
The SSO module provides convenience methods for working with the WorkOS SSO platform. You'll need a valid API key, a project ID, and to have created an SSO connection on your WorkOS dashboard.
Constant Summary collapse
Instance Attribute Summary
Attributes included from Base
Class Method Summary collapse
-
.authorization_url(project_id:, redirect_uri:, domain: nil, provider: nil, state: {}) ⇒ String
Generate an Oauth2 authorization URL where your users will authenticate using the configured SSO Identity Provider.
-
.profile(code:, project_id:) ⇒ WorkOS::Profile
Fetch the profile details for the authenticated SSO user.
-
.promote_draft_connection(token:) ⇒ Bool
Promote a DraftConnection created via the WorkOS.js embed such that the Enterprise users can begin signing into your application.
Methods included from Client
client, execute_request, handle_error_response, post_request, user_agent
Class Method Details
.authorization_url(project_id:, redirect_uri:, domain: nil, provider: nil, state: {}) ⇒ String
Generate an Oauth2 authorization URL where your users will authenticate using the configured SSO Identity Provider.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/workos/sso.rb', line 62 def ( project_id:, redirect_uri:, domain: nil, provider: nil, state: {} ) validate_domain_and_provider(provider: provider, domain: domain) query = URI.encode_www_form({ client_id: project_id, redirect_uri: redirect_uri, response_type: 'code', state: state, domain: domain, provider: provider, }.compact) "https://#{WorkOS::API_HOSTNAME}/sso/authorize?#{query}" end |
.profile(code:, project_id:) ⇒ WorkOS::Profile
Fetch the profile details for the authenticated SSO user.
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/workos/sso.rb', line 108 def profile(code:, project_id:) body = { client_id: project_id, client_secret: WorkOS.key!, grant_type: 'authorization_code', code: code, } response = client.request(post_request(path: '/sso/token', body: body)) check_and_raise_profile_error(response: response) WorkOS::Profile.new(response.body) end |
.promote_draft_connection(token:) ⇒ Bool
Promote a DraftConnection created via the WorkOS.js embed such that the Enterprise users can begin signing into your application.
you by the WorkOS.js embed
142 143 144 145 146 147 148 149 150 |
# File 'lib/workos/sso.rb', line 142 def promote_draft_connection(token:) request = bearer_post_request( path: "/draft_connections/#{token}/activate", ) response = client.request(request) response.is_a? Net::HTTPSuccess end |