Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/workos.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@
require "zeitwerk"

module WorkOS
# Sentinel default for nullable optional parameters. Distinguishes an
# omitted argument ("leave unchanged") from an explicit `nil`, which
# clears the field by sending JSON `null`.
OMIT = Object.new

def OMIT.inspect
"WorkOS::OMIT"
end

OMIT.freeze
end

loader = Zeitwerk::Loader.for_gem
require_relative "workos/inflections"
loader.inflector.inflect(WORKOS_INFLECTIONS)
loader.collapse("#{__dir__}/workos/admin_portal")
loader.collapse("#{__dir__}/workos/agents")
loader.collapse("#{__dir__}/workos/api_keys")
loader.collapse("#{__dir__}/workos/audit_logs")
loader.collapse("#{__dir__}/workos/authorization")
Expand Down
99 changes: 73 additions & 26 deletions lib/workos/sso.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# This file is auto-generated by oagen. Do not edit.

require "json"
require "uri"

module WorkOS
class SSO
Expand Down Expand Up @@ -106,6 +107,74 @@ def delete_connection(
nil
end

# Initiate SSO
# Builds the URL client-side; no HTTP request is made.
# @param provider_scopes [Array<String>, nil] Additional scopes to request from the identity provider. Applicable when using OAuth or OpenID Connect connections.
# @param provider_query_params [Hash{String => String}, nil] Key/value pairs of query parameters to pass to the OAuth provider. Only applicable when using OAuth connections.
# @param client_id [String, nil] The unique identifier of the WorkOS environment client. Defaults to the client's configured client_id.
# @param domain [String, nil] Deprecated. Use `connection` or `organization` instead. Used to initiate SSO for a connection by domain. The domain must be associated with a connection in your WorkOS environment.
# @param provider [WorkOS::Types::SSOProvider, nil] Used to initiate OAuth authentication with various providers.
# @param redirect_uri [String] Where to redirect the user after they complete the authentication process. You must use one of the redirect URIs configured via the [Redirects](https://dashboard.workos.com/redirects) page on the dashboard.
# @param state [String, nil] An optional parameter that can be used to encode arbitrary information to help restore application state between redirects. If included, the redirect URI received from WorkOS will contain the exact `state` that was passed.
# @param connection [String, nil] Used to initiate SSO for a connection. The value should be a WorkOS connection ID. You can persist the WorkOS connection ID with application user or team identifiers. WorkOS will use the connection indicated by the connection parameter to direct the user to the corresponding IdP for authentication.
# @param organization [String, nil] Used to initiate SSO for an organization. The value should be a WorkOS organization ID. You can persist the WorkOS organization ID with application user or team identifiers. WorkOS will use the organization ID to determine the appropriate connection and the IdP to direct the user to for authentication.
# @param domain_hint [String, nil] Can be used to pre-fill the domain field when initiating authentication with Microsoft OAuth or with a Google SAML connection type.
# @param login_hint [String, nil] Can be used to pre-fill the username/email address field of the IdP sign-in page for the user, if you know their username ahead of time. Currently supported for OAuth, OpenID Connect, Okta, Entra ID, and custom SAML connections.
# @param nonce [String, nil] A random string generated by the client that is used to mitigate replay attacks.
# @param prompt [String, nil] If set to `login`, forces re-authentication at the identity provider. For SAML connections this sets `ForceAuthn="true"` in the SAML request.
# @return [String]
def get_authorization_url(
redirect_uri:,
provider_scopes: nil,
provider_query_params: nil,
client_id: nil,
domain: nil,
provider: nil,
state: nil,
connection: nil,
organization: nil,
domain_hint: nil,
login_hint: nil,
nonce: nil,
prompt: nil
)
params = {
"provider_scopes" => provider_scopes,
"provider_query_params" => provider_query_params,
"client_id" => client_id,
"domain" => domain,
"provider" => provider,
"redirect_uri" => redirect_uri,
"state" => state,
"connection" => connection,
"organization" => organization,
"domain_hint" => domain_hint,
"login_hint" => login_hint,
"nonce" => nonce,
"prompt" => prompt
}.compact
params["provider_scopes"] = provider_scopes.join(",") unless provider_scopes.nil?
params["provider_query_params"] = JSON.generate(provider_query_params) unless provider_query_params.nil?
params["response_type"] = "code"
params["client_id"] = @client.client_id if !params.key?("client_id") && !@client.client_id.nil?
uri = URI.join(@client.base_url, "/sso/authorize")
uri.query = URI.encode_www_form(params) unless params.empty?
uri.to_s
end

# Logout Redirect
# Builds the URL client-side; no HTTP request is made.
# @param token [String] The logout token returned from the [Logout Authorize](https://workos.com/docs/reference/sso/logout/authorize) endpoint.
# @return [String]
def get_logout_url(token:)
params = {
"token" => token
}
uri = URI.join(@client.base_url, "/sso/logout")
uri.query = URI.encode_www_form(params) unless params.empty?
uri.to_s
end

# Logout Authorize
# @param profile_id [String] The unique ID of the profile to log out.
# @param request_options [Hash] (see WorkOS::Types::RequestOptions)
Expand Down Expand Up @@ -171,32 +240,10 @@ def get_profile_and_token(
end

# @oagen-ignore-start — non-spec helpers (hand-maintained)
# H14 — Build an SSO authorization URL (client-side, no HTTP call).
# Overrides the generated method which incorrectly hits the API.
def get_authorization_url(redirect_uri:, client_id: nil, state: nil, connection: nil,
organization: nil, provider: nil, domain_hint: nil,
login_hint: nil, nonce: nil, provider_scopes: nil,
provider_query_params: nil, **)
cid = client_id || @client.client_id
raise ArgumentError, "client_id is required (set on Client or pass explicitly)" if cid.nil? || cid.empty?
params = {
"client_id" => cid,
"redirect_uri" => redirect_uri,
"response_type" => "code",
"state" => state,
"connection" => connection,
"organization" => organization,
"provider" => provider,
"domain_hint" => domain_hint,
"login_hint" => login_hint,
"nonce" => nonce
}.compact
params["provider_scopes"] = Array(provider_scopes).join(",") if provider_scopes
if provider_query_params.is_a?(Hash) && !provider_query_params.empty?
params["provider_query_params"] = JSON.generate(provider_query_params)
end
build_url("/sso/authorize", params)
end
# H14 (sso_authorization_url) is provided by the generated
# `get_authorization_url` url-builder method, which accepts an optional
# per-call `client_id` override falling back to the client's configured
# value; no hand-maintained override is needed here.

# H15 — SSO authorization URL with auto-generated PKCE pair + state.
# Returns [url, code_verifier, state].
Expand Down
Loading
Loading