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.
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:) query = URI.encode_www_form( client_id: project_id, client_secret: WorkOS.key!, grant_type: 'authorization_code', code: code, ) response = client.request(post_request(path: "/sso/token?#{query}")) check_and_raise_profile_error(response: response) WorkOS::Profile.new(response.body) end |