Class: SSOReady::AsyncSAMLClient

Inherits:
Object
  • Object
show all
Defined in:
lib/ssoready/saml/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ SSOReady::AsyncSAMLClient

Parameters:



108
109
110
# File 'lib/ssoready/saml/client.rb', line 108

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientSSOReady::AsyncRequestClient (readonly)



104
105
106
# File 'lib/ssoready/saml/client.rb', line 104

def request_client
  @request_client
end

Instance Method Details

#get_saml_redirect_url(saml_connection_id: nil, organization_id: nil, organization_external_id: nil, state: nil, request_options: nil) ⇒ SSOReady::GetSAMLRedirectURLResponse

Gets a SAML initiation URL to redirect your users to.

Examples:

api = SSOReady::Client.new(
  base_url: "https://api.example.com",
  environment: SSOReady::Environment::DEFAULT,
  api_key: "YOUR_AUTH_TOKEN"
)
api.saml.get_saml_redirect_url(organization_external_id: "my_custom_external_id")

Parameters:

  • saml_connection_id (String) (defaults to: nil)

    The SAML connection to start a SAML login for. One of ‘samlConnectionId`, `organizationId`, or `organizationExternalId` must be specified.

  • organization_id (String) (defaults to: nil)

    The ID of the organization to start a SAML login for. The primary SAML connection in this organization will be used for logins. One of ‘samlConnectionId`, `organizationId`, or `organizationExternalId` must be specified.

  • organization_external_id (String) (defaults to: nil)

    The ‘externalId` of the organization to start a SAML login for. The primary SAML connection in this organization will be used for logins. One of `samlConnectionId`, `organizationId`, or `organizationExternalId` must be specified.

  • state (String) (defaults to: nil)

    This string will be returned back to you when you redeem this login’s SAML access code. You can do anything you like with this ‘state`, but the most common use-case is to keep track of where to redirect your user back to after logging in with SAML.

  • request_options (SSOReady::RequestOptions) (defaults to: nil)

Returns:



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/ssoready/saml/client.rb', line 171

def get_saml_redirect_url(saml_connection_id: nil, organization_id: nil, organization_external_id: nil, state: nil,
                          request_options: nil)
  Async do
    response = @request_client.conn.post do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
      req.headers = {
    **(req.headers || {}),
    **@request_client.get_headers,
    **(request_options&.additional_headers || {})
      }.compact
      unless request_options.nil? || request_options&.additional_query_parameters.nil?
        req.params = { **(request_options&.additional_query_parameters || {}) }.compact
      end
      req.body = {
        **(request_options&.additional_body_parameters || {}),
        samlConnectionId: saml_connection_id,
        organizationId: organization_id,
        organizationExternalId: organization_external_id,
        state: state
      }.compact
      req.url "#{@request_client.get_url(request_options: request_options)}/v1/saml/redirect"
    end
    SSOReady::GetSAMLRedirectURLResponse.from_json(json_object: response.body)
  end
end

#redeem_saml_access_code(saml_access_code: nil, request_options: nil) ⇒ SSOReady::RedeemSAMLAccessCodeResponse

Exchanges a SAML access code for details about your user’s SAML login details.

Examples:

api = SSOReady::Client.new(
  base_url: "https://api.example.com",
  environment: SSOReady::Environment::DEFAULT,
  api_key: "YOUR_AUTH_TOKEN"
)
api.saml.redeem_saml_access_code(saml_access_code: "saml_access_code_...")

Parameters:

  • saml_access_code (String) (defaults to: nil)

    The SAML access code to redeem.

  • request_options (SSOReady::RequestOptions) (defaults to: nil)

Returns:



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/ssoready/saml/client.rb', line 124

def redeem_saml_access_code(saml_access_code: nil, request_options: nil)
  Async do
    response = @request_client.conn.post do |req|
      req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
      req.headers["Authorization"] = request_options.api_key unless request_options&.api_key.nil?
      req.headers = {
    **(req.headers || {}),
    **@request_client.get_headers,
    **(request_options&.additional_headers || {})
      }.compact
      unless request_options.nil? || request_options&.additional_query_parameters.nil?
        req.params = { **(request_options&.additional_query_parameters || {}) }.compact
      end
      req.body = { **(request_options&.additional_body_parameters || {}), samlAccessCode: saml_access_code }.compact
      req.url "#{@request_client.get_url(request_options: request_options)}/v1/saml/redeem"
    end
    SSOReady::RedeemSAMLAccessCodeResponse.from_json(json_object: response.body)
  end
end