class StytchB2B::Discovery::Organizations

def create(

The type of this field is nilable +PrimaryRequired+ (+object+).
Information about the primary authentication requirements of the Organization.
primary_required::
The type of this field is nilable +MfaRequired+ (+object+).
Information about the MFA requirements of the Organization and the Member's options for fulfilling MFA.
mfa_required::
The type of this field is nilable +Organization+ (+object+).
The [Organization object](https://stytch.com/docs/b2b/api/organization-object).
organization::
The type of this field is nilable +MemberSession+ (+object+).
The [Session object](https://stytch.com/docs/b2b/api/session-object).
member_session::
The type of this field is +Integer+.
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.
status_code::
The type of this field is +String+.
The returned Intermediate Session Token is identical to the one that was originally passed in to the request. If this value is non-empty, the member must complete an MFA step to finish logging in to the Organization. The token can be used with the [OTP SMS Authenticate endpoint](https://stytch.com/docs/b2b/api/authenticate-otp-sms), [TOTP Authenticate endpoint](https://stytch.com/docs/b2b/api/authenticate-totp), or [Recovery Codes Recover endpoint](https://stytch.com/docs/b2b/api/recovery-codes-recover) to complete an MFA flow and log in to the Organization. It can also be used with the [Exchange Intermediate Session endpoint](https://stytch.com/docs/b2b/api/exchange-intermediate-session) to join a specific Organization that allows the factors represented by the intermediate session token; or the [Create Organization via Discovery endpoint](https://stytch.com/docs/b2b/api/create-organization-via-discovery) to create a new Organization and Member.
intermediate_session_token::
The type of this field is +Boolean+.
Indicates whether the Member is fully authenticated. If false, the Member needs to complete an MFA step to log in to the Organization.
member_authenticated::
The type of this field is +Member+ (+object+).
The [Member object](https://stytch.com/docs/b2b/api/member-object)
member::
The type of this field is +String+.
The JSON Web Token (JWT) for a given Stytch Session.
session_jwt::
The type of this field is +String+.
A secret token for a given Stytch Session.
session_token::
The type of this field is +String+.
Globally unique UUID that identifies a specific Member.
member_id::
The type of this field is +String+.
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.
request_id::
An object with the following fields:
== Returns:

The type of this field is nilable +object+.
A map of allowed OAuth tenants. If this field is not passed in, the Organization will not allow JIT provisioning by OAuth Tenant. Allowed keys are "slack", "hubspot", and "github".
allowed_oauth_tenants::
The type of this field is nilable +String+.

`NOT_ALLOWED` – disable JIT provisioning by OAuth Tenant.

`RESTRICTED` – only new Members with tenants in `allowed_oauth_tenants` can JIT provision via tenant.

The authentication setting that controls how a new Member can JIT provision into an organization by tenant. The accepted values are:
oauth_tenant_jit_provisioning::
The type of this field is nilable list of +String+.

The list's accepted values are: `sms_otp` and `totp`.
An array of allowed MFA authentication methods. This list is enforced when `mfa_methods` is set to `RESTRICTED`.
allowed_mfa_methods::
The type of this field is nilable +String+.

`RESTRICTED` – only methods that comply with `allowed_mfa_methods` can be used for authentication. This setting does not apply to Members with `is_breakglass` set to `true`.

`ALL_ALLOWED` – the default setting which allows all authentication methods to be used.

The setting that controls which MFA methods can be used by Members of an Organization. The accepted values are:
mfa_methods::
The type of this field is nilable list of +EmailImplicitRoleAssignment+ (+object+).
for more information about role assignment.
associated Role, regardless of their login method. See the [RBAC guide](https://stytch.com/docs/b2b/guides/rbac/role-assignment)
For each domain-Role pair, all Members whose email addresses have the specified email domain will be granted the
Implicit role assignments based off of email domains.
rbac_email_implicit_role_assignments::
The type of this field is nilable +String+.

`OPTIONAL` – The default value. The Organization does not require MFA by default for all Members. Members will be required to complete MFA only if their `mfa_enrolled` status is set to true.

`REQUIRED_FOR_ALL` – All Members within the Organization will be required to complete MFA every time they wish to log in. However, any active Session that existed prior to this setting change will remain valid.

The setting that controls the MFA policy for all Members in the Organization. The accepted values are:
mfa_policy::
The type of this field is nilable list of +String+.

The list's accepted values are: `sso`, `magic_link`, `password`, `google_oauth`, and `microsoft_oauth`.
An array of allowed authentication methods. This list is enforced when `auth_methods` is set to `RESTRICTED`.
allowed_auth_methods::
The type of this field is nilable +String+.

`RESTRICTED` – only methods that comply with `allowed_auth_methods` can be used for authentication. This setting does not apply to Members with `is_breakglass` set to `true`.

`ALL_ALLOWED` – the default setting which allows all authentication methods to be used.

The setting that controls which authentication methods can be used by Members of an Organization. The accepted values are:
auth_methods::
The type of this field is nilable +String+.

`NOT_ALLOWED` – disable email invites.

`RESTRICTED` – only new Members with verified emails that comply with `email_allowed_domains` can be invited via email.

`ALL_ALLOWED` – any new Member can be invited to join via email.

The authentication setting that controls how a new Member can be invited to an organization by email. The accepted values are:
email_invites::
The type of this field is nilable +String+.

`NOT_ALLOWED` – disable JIT provisioning via Email Magic Link and OAuth.

`RESTRICTED` – only new Members with verified emails that comply with `email_allowed_domains` can be provisioned upon authentication via Email Magic Link or OAuth.

The authentication setting that controls how a new Member can be provisioned by authenticating via Email Magic Link or OAuth. The accepted values are:
email_jit_provisioning::
The type of this field is nilable list of +String+.
Common domains such as `gmail.com` are not allowed. See the [common email domains resource](https://stytch.com/docs/b2b/api/common-email-domains) for the full list.


An array of email domains that allow invites or JIT provisioning for new Members. This list is enforced when either `email_invites` or `email_jit_provisioning` is set to `RESTRICTED`.
email_allowed_domains::
The type of this field is nilable +String+.

`NOT_ALLOWED` – disable JIT provisioning via SSO.

`RESTRICTED` – only new Members with SSO logins that comply with `sso_jit_provisioning_allowed_connections` can be provisioned upon authentication.

`ALL_ALLOWED` – new Members will be automatically provisioned upon successful authentication via any of the Organization's `sso_active_connections`.

The authentication setting that controls the JIT provisioning of Members when authenticating via SSO. The accepted values are:
sso_jit_provisioning::
The type of this field is nilable +object+.
An arbitrary JSON object for storing application-specific data or identity-provider-specific data.
trusted_metadata::
The type of this field is nilable +String+.
The image URL of the Organization logo.
organization_logo_url::
The type of this field is nilable +String+.
The unique URL slug of the Organization. A minimum of two characters is required. The slug only accepts alphanumeric characters and the following reserved characters: `-` `.` `_` `~`. If the slug is not specified, a default slug will be created based on the email used to initiate the discovery flow. If the email domain is a common email provider such as gmail.com, or if the email is a .edu email, the organization slug will be generated based on the name portion of the email. Otherwise, the organization slug will be generated based on the email domain.
organization_slug::
The type of this field is nilable +String+.
The name of the Organization. If the name is not specified, a default name will be created based on the email used to initiate the discovery flow. If the email domain is a common email provider such as gmail.com, or if the email is a .edu email, the organization name will be generated based on the name portion of the email. Otherwise, the organization name will be generated based on the email domain.
organization_name::
The type of this field is nilable +object+.
Total custom claims size cannot exceed four kilobytes.
delete a key, supply a null value. Custom claims made with reserved claims (`iss`, `sub`, `aud`, `exp`, `nbf`, `iat`, `jti`) will be ignored.
`session_duration_minutes`. Claims will be included on the Session object and in the JWT. To update a key in an existing Session, supply a new value. To
Add a custom claims map to the Session being authenticated. Claims are only created if a Session is initialized by providing a value in
session_custom_claims::
The type of this field is nilable +Integer+.
to use the Stytch session product, you can ignore the session fields in the response.
If the `session_duration_minutes` parameter is not specified, a Stytch session will be created with a 60 minute duration. If you don't want

If a `session_token` or `session_jwt` is provided then a successful authentication will continue to extend the session this many minutes.

This value must be a minimum of 5 and a maximum of 527040 minutes (366 days).

five minutes regardless of the underlying session duration, and will need to be refreshed over time.
returning both an opaque `session_token` and `session_jwt` for this session. Remember that the `session_jwt` will have a fixed lifetime of
Set the session lifetime to be this many minutes from now. This will start a new session if one doesn't already exist,
session_duration_minutes::
The type of this field is +String+.
The Intermediate Session Token. This token does not necessarily belong to a specific instance of a Member, but represents a bag of factors that may be converted to a member session. The token can be used with the [OTP SMS Authenticate endpoint](https://stytch.com/docs/b2b/api/authenticate-otp-sms), [TOTP Authenticate endpoint](https://stytch.com/docs/b2b/api/authenticate-totp), or [Recovery Codes Recover endpoint](https://stytch.com/docs/b2b/api/recovery-codes-recover) to complete an MFA flow and log in to the Organization. It can also be used with the [Exchange Intermediate Session endpoint](https://stytch.com/docs/b2b/api/exchange-intermediate-session) to join a specific Organization that allows the factors represented by the intermediate session token; or the [Create Organization via Discovery endpoint](https://stytch.com/docs/b2b/api/create-organization-via-discovery) to create a new Organization and Member.
intermediate_session_token::
== Parameters:

The `session_duration_minutes` and `session_custom_claims` parameters will be ignored.
The `intermediate_session_token` can also be used with the [Exchange Intermediate Session endpoint](https://stytch.com/docs/b2b/api/exchange-intermediate-session) or the [Create Organization via Discovery endpoint](https://stytch.com/docs/b2b/api/create-organization-via-discovery) to join a different Organization or create a new one.
The `intermediate_session_token` can be passed into the [OTP SMS Authenticate endpoint](https://stytch.com/docs/b2b/api/authenticate-otp-sms) to complete the MFA step and acquire a full member session.
The `intermediate_session_token` will not be consumed and instead will be returned in the response.
If the new Organization is created with a `mfa_policy` of `REQUIRED_FOR_ALL`, the newly created Member will need to complete an MFA step to log in to the Organization.

[RBAC guide](https://stytch.com/docs/b2b/guides/rbac/stytch-default) for more details on this Role.
The created by this endpoint will automatically be granted the `stytch_admin` Role. See the

This endpoint will also create an initial Member Session for the newly created Member.

This operation consumes the Intermediate Session.

[Organization](https://stytch.com/docs/b2b/api/organization-object) and [Member](https://stytch.com/docs/b2b/api/member-object).
If an end user does not want to join any already-existing, or has no possible Organizations to join, this endpoint can be used to create a new
def create(
  intermediate_session_token:,
  session_duration_minutes: nil,
  session_custom_claims: nil,
  organization_name: nil,
  organization_slug: nil,
  organization_logo_url: nil,
  trusted_metadata: nil,
  sso_jit_provisioning: nil,
  email_allowed_domains: nil,
  email_jit_provisioning: nil,
  email_invites: nil,
  auth_methods: nil,
  allowed_auth_methods: nil,
  mfa_policy: nil,
  rbac_email_implicit_role_assignments: nil,
  mfa_methods: nil,
  allowed_mfa_methods: nil,
  oauth_tenant_jit_provisioning: nil,
  allowed_oauth_tenants: nil
)
  headers = {}
  request = {
    intermediate_session_token: intermediate_session_token
  }
  request[:session_duration_minutes] = session_duration_minutes unless session_duration_minutes.nil?
  request[:session_custom_claims] = session_custom_claims unless session_custom_claims.nil?
  request[:organization_name] = organization_name unless organization_name.nil?
  request[:organization_slug] = organization_slug unless organization_slug.nil?
  request[:organization_logo_url] = organization_logo_url unless organization_logo_url.nil?
  request[:trusted_metadata] = trusted_metadata unless trusted_metadata.nil?
  request[:sso_jit_provisioning] = sso_jit_provisioning unless sso_jit_provisioning.nil?
  request[:email_allowed_domains] = email_allowed_domains unless email_allowed_domains.nil?
  request[:email_jit_provisioning] = email_jit_provisioning unless email_jit_provisioning.nil?
  request[:email_invites] = email_invites unless email_invites.nil?
  request[:auth_methods] = auth_methods unless auth_methods.nil?
  request[:allowed_auth_methods] = allowed_auth_methods unless allowed_auth_methods.nil?
  request[:mfa_policy] = mfa_policy unless mfa_policy.nil?
  request[:rbac_email_implicit_role_assignments] = rbac_email_implicit_role_assignments unless rbac_email_implicit_role_assignments.nil?
  request[:mfa_methods] = mfa_methods unless mfa_methods.nil?
  request[:allowed_mfa_methods] = allowed_mfa_methods unless allowed_mfa_methods.nil?
  request[:oauth_tenant_jit_provisioning] = oauth_tenant_jit_provisioning unless oauth_tenant_jit_provisioning.nil?
  request[:allowed_oauth_tenants] = allowed_oauth_tenants unless allowed_oauth_tenants.nil?
  post_request('/v1/b2b/discovery/organizations/create', request, headers)
end

def initialize(connection)

def initialize(connection)
  @connection = connection
end

def list(

The type of this field is nilable +String+.
If the intermediate session token is associated with a specific Organization, that Organization ID will be returned here. The Organization ID will be null if the intermediate session token was generated by a email magic link discovery or OAuth discovery flow. If a session token or session JWT is provided, the Organization ID hint will be null.
organization_id_hint::
The type of this field is +Integer+.
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.
status_code::
The type of this field is list of +DiscoveredOrganization+ (+object+).
c) The Organization has at least one other Member with a verified email address with the same domain as the end user (to prevent phishing attacks).

b) The Organizations' allowed domains list contains the Member's email domain.

a) The Organization allows JIT provisioning.

3. The end user can join the Organization because:
2. The end user is invited to the Organization.
1. The end user is already a Member of the Organization.
Note that Organizations will only appear here under any of the following conditions:

An array of `discovered_organization` objects tied to the `intermediate_session_token`, `session_token`, or `session_jwt`. See the [Discovered Organization Object](https://stytch.com/docs/b2b/api/discovered-organization-object) for complete details.
discovered_organizations::
The type of this field is +String+.
The email address.
email_address::
The type of this field is +String+.
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.
request_id::
An object with the following fields:
== Returns:

The type of this field is nilable +String+.
The JSON Web Token (JWT) for a given Stytch Session.
session_jwt::
The type of this field is nilable +String+.
A secret token for a given Stytch Session.
session_token::
The type of this field is nilable +String+.
The Intermediate Session Token. This token does not necessarily belong to a specific instance of a Member, but represents a bag of factors that may be converted to a member session. The token can be used with the [OTP SMS Authenticate endpoint](https://stytch.com/docs/b2b/api/authenticate-otp-sms), [TOTP Authenticate endpoint](https://stytch.com/docs/b2b/api/authenticate-totp), or [Recovery Codes Recover endpoint](https://stytch.com/docs/b2b/api/recovery-codes-recover) to complete an MFA flow and log in to the Organization. It can also be used with the [Exchange Intermediate Session endpoint](https://stytch.com/docs/b2b/api/exchange-intermediate-session) to join a specific Organization that allows the factors represented by the intermediate session token; or the [Create Organization via Discovery endpoint](https://stytch.com/docs/b2b/api/create-organization-via-discovery) to create a new Organization and Member.
intermediate_session_token::
== Parameters:

This operation does not consume the Intermediate Session or Session Token passed in.

It will return an error if multiple are present.
This endpoint requires either an `intermediate_session_token`, `session_jwt` or `session_token` be included in the request.

and any membership can be assumed by calling the [Exchange Intermediate Session](https://stytch.com/docs/b2b/api/exchange-intermediate-session) endpoint.
and `eligible_to_join_by_email_domain` - will be returned,
When an Intermediate Session is passed in, all relationship types - `active_member`, `pending_member`, `invited_member`,

will be returned, and any membership can be assumed by calling the [Exchange Session](https://stytch.com/docs/b2b/api/exchange-session) endpoint.
When a Member Session is passed in, relationships with a type of `active_member`, `pending_member`, or `invited_member`

List all possible organization relationships connected to a [Member Session](https://stytch.com/docs/b2b/api/session-object) or Intermediate Session.
def list(
  intermediate_session_token: nil,
  session_token: nil,
  session_jwt: nil
)
  headers = {}
  request = {}
  request[:intermediate_session_token] = intermediate_session_token unless intermediate_session_token.nil?
  request[:session_token] = session_token unless session_token.nil?
  request[:session_jwt] = session_jwt unless session_jwt.nil?
  post_request('/v1/b2b/discovery/organizations', request, headers)
end