Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add external connection endpoints #138

Merged
merged 2 commits into from
Oct 10, 2024
Merged
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
10 changes: 8 additions & 2 deletions lib/stytch/b2b_organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,9 @@ def delete_password(
# member_id::
# Globally unique UUID that identifies a specific Member. The `member_id` is critical to perform operations on a Member, so be sure to preserve this value.
# The type of this field is +String+.
# include_deleted::
# Whether to include deleted Members in the response. Defaults to false.
# The type of this field is nilable +Boolean+.
#
# == Returns:
# An object with the following fields:
Expand All @@ -1123,10 +1126,13 @@ def delete_password(
# The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
# The type of this field is +Integer+.
def dangerously_get(
member_id:
member_id:,
include_deleted: nil
)
headers = {}
query_params = {}
query_params = {
include_deleted: include_deleted
}
request = request_with_query_params("/v1/b2b/organizations/members/dangerously_get/#{member_id}", query_params)
get_request(request, headers)
end
Expand Down
168 changes: 165 additions & 3 deletions lib/stytch/b2b_sso.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ def to_headers
end

include Stytch::RequestHelper
attr_reader :oidc, :saml
attr_reader :oidc, :saml, :external

def initialize(connection)
@connection = connection

@oidc = StytchB2B::SSO::OIDC.new(@connection)
@saml = StytchB2B::SSO::SAML.new(@connection)
@external = StytchB2B::SSO::External.new(@connection)
end

# Get all SSO Connections owned by the organization.
Expand All @@ -77,7 +78,7 @@ def initialize(connection)
# The list of [OIDC Connections](https://stytch.com/docs/b2b/api/oidc-connection-object) owned by this organization.
# The type of this field is list of +OIDCConnection+ (+object+).
# external_connections::
# (no documentation yet)
# The list of [External Connections](https://stytch.com/docs/b2b/api/external-connection-object) owned by this organization.
# The type of this field is list of +Connection+ (+object+).
# status_code::
# The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
Expand All @@ -103,7 +104,7 @@ def get_connections(
# The organization ID that the SSO connection belongs to.
# The type of this field is +String+.
# connection_id::
# The ID of the SSO connection. Both SAML and OIDC connection IDs can be provided.
# The ID of the SSO connection. SAML, OIDC, and External connection IDs can be provided.
# The type of this field is +String+.
#
# == Returns:
Expand Down Expand Up @@ -759,5 +760,166 @@ def delete_verification_certificate(
delete_request("/v1/b2b/sso/saml/#{organization_id}/connections/#{connection_id}/verification_certificates/#{certificate_id}", headers)
end
end

class External
class CreateConnectionRequestOptions
# Optional authorization object.
# Pass in an active Stytch Member session token or session JWT and the request
# will be run using that member's permissions.
attr_accessor :authorization

def initialize(
authorization: nil
)
@authorization = authorization
end

def to_headers
headers = {}
headers.merge!(@authorization.to_headers) if authorization
headers
end
end

class UpdateConnectionRequestOptions
# Optional authorization object.
# Pass in an active Stytch Member session token or session JWT and the request
# will be run using that member's permissions.
attr_accessor :authorization

def initialize(
authorization: nil
)
@authorization = authorization
end

def to_headers
headers = {}
headers.merge!(@authorization.to_headers) if authorization
headers
end
end

include Stytch::RequestHelper

def initialize(connection)
@connection = connection
end

# Create a new External SSO Connection.
#
# == Parameters:
# organization_id::
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value.
# The type of this field is +String+.
# external_organization_id::
# Globally unique UUID that identifies a different Organization within your Project.
# The type of this field is +String+.
# external_connection_id::
# Globally unique UUID that identifies a specific SSO connection configured for a different Organization in your Project.
# The type of this field is +String+.
# display_name::
# A human-readable display name for the connection.
# The type of this field is nilable +String+.
# connection_implicit_role_assignments::
# (no documentation yet)
# The type of this field is nilable list of +SAMLConnectionImplicitRoleAssignment+.
# group_implicit_role_assignments::
# (no documentation yet)
# The type of this field is nilable list of +SAMLGroupImplicitRoleAssignment+.
#
# == Returns:
# An object with the following fields:
# request_id::
# Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
# The type of this field is +String+.
# status_code::
# The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
# The type of this field is +Integer+.
# connection::
# The `External Connection` object affected by this API call. See the [External Connection Object](https://stytch.com/docs/b2b/api/external-connection-object) for complete response field details.
# The type of this field is nilable +Connection+ (+object+).
#
# == Method Options:
# This method supports an optional +StytchB2B::SSO::External::CreateConnectionRequestOptions+ object which will modify the headers sent in the HTTP request.
def create_connection(
organization_id:,
external_organization_id:,
external_connection_id:,
display_name: nil,
connection_implicit_role_assignments: nil,
group_implicit_role_assignments: nil,
method_options: nil
)
headers = {}
headers = headers.merge(method_options.to_headers) unless method_options.nil?
request = {
external_organization_id: external_organization_id,
external_connection_id: external_connection_id
}
request[:display_name] = display_name unless display_name.nil?
request[:connection_implicit_role_assignments] = connection_implicit_role_assignments unless connection_implicit_role_assignments.nil?
request[:group_implicit_role_assignments] = group_implicit_role_assignments unless group_implicit_role_assignments.nil?

post_request("/v1/b2b/sso/external/#{organization_id}", request, headers)
end

# Updates an existing External SSO connection.
#
# == Parameters:
# organization_id::
# Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value.
# The type of this field is +String+.
# connection_id::
# Globally unique UUID that identifies a specific External SSO Connection.
# The type of this field is +String+.
# display_name::
# A human-readable display name for the connection.
# The type of this field is nilable +String+.
# external_connection_implicit_role_assignments::
# All Members who log in with this External connection will implicitly receive the specified Roles. See the [RBAC guide](https://stytch.com/docs/b2b/guides/rbac/role-assignment) for more information about role assignment.Implicit role assignments are not supported for External connections if the underlying SSO connection is an OIDC connection.
# The type of this field is nilable list of +ConnectionImplicitRoleAssignment+.
# external_group_implicit_role_assignments::
# Defines the names of the groups
# that grant specific role assignments. For each group-Role pair, if a Member logs in with this external connection and
# belongs to the specified group, they will be granted the associated Role. See the
# [RBAC guide](https://stytch.com/docs/b2b/guides/rbac/role-assignment) for more information about role assignment.
# Before adding any group implicit role assignments to an external connection, you must add a "groups" key to the underlying SAML connection's
# `attribute_mapping`. Make sure that the SAML connection IdP is configured to correctly send the group information. Implicit role assignments are not supported
# for External connections if the underlying SSO connection is an OIDC connection.
# The type of this field is nilable list of +GroupImplicitRoleAssignment+.
#
# == Returns:
# An object with the following fields:
# request_id::
# Globally unique UUID that is returned with every API call. This value is important to log for debugging purposes; we may ask for this value to help identify a specific API call when helping you debug an issue.
# The type of this field is +String+.
# status_code::
# The HTTP status code of the response. Stytch follows standard HTTP response status code patterns, e.g. 2XX values equate to success, 3XX values are redirects, 4XX are client errors, and 5XX are server errors.
# The type of this field is +Integer+.
# connection::
# The `External Connection` object affected by this API call. See the [External Connection Object](https://stytch.com/docs/b2b/api/external-connection-object) for complete response field details.
# The type of this field is nilable +Connection+ (+object+).
#
# == Method Options:
# This method supports an optional +StytchB2B::SSO::External::UpdateConnectionRequestOptions+ object which will modify the headers sent in the HTTP request.
def update_connection(
organization_id:,
connection_id:,
display_name: nil,
external_connection_implicit_role_assignments: nil,
external_group_implicit_role_assignments: nil,
method_options: nil
)
headers = {}
headers = headers.merge(method_options.to_headers) unless method_options.nil?
request = {}
request[:display_name] = display_name unless display_name.nil?
request[:external_connection_implicit_role_assignments] = external_connection_implicit_role_assignments unless external_connection_implicit_role_assignments.nil?
request[:external_group_implicit_role_assignments] = external_group_implicit_role_assignments unless external_group_implicit_role_assignments.nil?

put_request("/v1/b2b/sso/external/#{organization_id}/connections/#{connection_id}", request, headers)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/stytch/sessions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def revoke(
#
# == Parameters:
# session_token::
# The `session_token` associated with a User's existing Session.
# The authorization token Stytch will pass in to the external userinfo endpoint.
# The type of this field is +String+.
# session_duration_minutes::
# Set the session lifetime to be this many minutes from now. This will start a new session if one doesn't already exist,
Expand Down
2 changes: 1 addition & 1 deletion lib/stytch/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Stytch
VERSION = '9.7.0'
VERSION = '9.8.0'
end
Loading