Class: SSOReady::SAMLClient

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::SAMLClient

Parameters:



15
16
17
# File 'lib/ssoready/saml/client.rb', line 15

def initialize(request_client:)
  @request_client = request_client
end

Instance Attribute Details

#request_clientSSOReady::RequestClient (readonly)



11
12
13
# File 'lib/ssoready/saml/client.rb', line 11

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:



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/ssoready/saml/client.rb', line 76

def get_saml_redirect_url(saml_connection_id: nil, organization_id: nil, organization_external_id: nil, state: nil,
                          request_options: nil)
  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

#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:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ssoready/saml/client.rb', line 31

def redeem_saml_access_code(saml_access_code: nil, request_options: nil)
  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