Module: WorkOS::SSO
- Extended by:
- Client, Deprecation
- Defined in:
- lib/workos/sso.rb
Overview
The SSO module provides convenience methods for working with the WorkOS SSO platform. You’ll need a valid API key, a client ID, and to have created an SSO connection on your WorkOS dashboard.
Constant Summary collapse
Class Method Summary collapse
-
.authorization_url(redirect_uri:, client_id: nil, domain: nil, domain_hint: nil, login_hint: nil, provider: nil, connection: nil, organization: nil, state: '') ⇒ String
Generate an Oauth2 authorization URL where your users will authenticate using the configured SSO Identity Provider.
-
.delete_connection(id:) ⇒ Bool
Delete a Connection.
-
.get_connection(id:) ⇒ WorkOS::Connection
Get a Connection.
-
.get_profile(access_token:) ⇒ Object
rubocop:enable Metrics/ParameterLists.
-
.list_connections(options = {}) ⇒ Hash
Retrieve connections.
-
.profile_and_token(code:, client_id: nil) ⇒ WorkOS::ProfileAndToken
Fetch the profile details for the authenticated SSO user.
Methods included from Client
client, delete_request, execute_request, get_request, handle_error_response, post_request, put_request, user_agent
Methods included from Deprecation
Class Method Details
.authorization_url(redirect_uri:, client_id: nil, domain: nil, domain_hint: nil, login_hint: nil, provider: nil, connection: nil, organization: nil, state: '') ⇒ String
Generate an Oauth2 authorization URL where your users will authenticate using the configured SSO Identity Provider.
‘GoogleOAuth’, and ‘MicrosoftOAuth’ are supported. rubocop:disable Metrics/ParameterLists
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/workos/sso.rb', line 56 def ( redirect_uri:, client_id: nil, domain: nil, domain_hint: nil, login_hint: nil, provider: nil, connection: nil, organization: nil, state: '' ) if domain warn_deprecation '[DEPRECATION] `domain` is deprecated. Please use `organization` instead.' end ( provider: provider, domain: domain, connection: connection, organization: organization, ) query = URI.encode_www_form({ client_id: client_id, redirect_uri: redirect_uri, response_type: 'code', state: state, domain: domain, domain_hint: domain_hint, login_hint: login_hint, provider: provider, connection: connection, organization: organization, }.compact) "https://#{WorkOS.config.api_hostname}/sso/authorize?#{query}" end |
.delete_connection(id:) ⇒ Bool
Delete a Connection
203 204 205 206 207 208 209 210 211 212 |
# File 'lib/workos/sso.rb', line 203 def delete_connection(id:) request = delete_request( auth: true, path: "/connections/#{id}", ) response = execute_request(request: request) response.is_a? Net::HTTPSuccess end |
.get_connection(id:) ⇒ WorkOS::Connection
Get a Connection
183 184 185 186 187 188 189 190 191 192 |
# File 'lib/workos/sso.rb', line 183 def get_connection(id:) request = get_request( auth: true, path: "/connections/#{id}", ) response = execute_request(request: request) WorkOS::Connection.new(response.body) end |
.get_profile(access_token:) ⇒ Object
rubocop:enable Metrics/ParameterLists
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/workos/sso.rb', line 96 def get_profile(access_token:) response = execute_request( request: get_request( path: '/sso/profile', auth: true, access_token: access_token, ), ) WorkOS::Profile.new(response.body) end |
.list_connections(options = {}) ⇒ Hash
Retrieve connections.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/workos/sso.rb', line 146 def list_connections( = {}) [:order] ||= 'desc' response = execute_request( request: get_request( path: '/connections', auth: true, params: , ), ) parsed_response = JSON.parse(response.body) connections = parsed_response['data'].map do |connection| ::WorkOS::Connection.new(connection.to_json) end WorkOS::Types::ListStruct.new( data: connections, list_metadata: parsed_response['listMetadata'], ) end |
.profile_and_token(code:, client_id: nil) ⇒ WorkOS::ProfileAndToken
Fetch the profile details for the authenticated SSO user.
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/workos/sso.rb', line 115 def profile_and_token(code:, client_id: nil) body = { client_id: client_id, client_secret: WorkOS.config.key!, grant_type: 'authorization_code', code: code, } response = client.request(post_request(path: '/sso/token', body: body)) check_and_raise_profile_and_token_error(response: response) WorkOS::ProfileAndToken.new(response.body) end |