<@U04UQ68083H> is there a way to define relationsh...
# ory-copilot
b
@chilly-king-10285 is there a way to define relationships that pertain to an entire Organization?
c
A message from kapa.ai
Yes, there is a way to define relationships that pertain to an entire organization in Ory. This can be done using the concept of "relationships" in Ory Permissions. A relationship consists of three elements: an object entity, a relation string, and a subject entity. Relationships represent real relationships between different entities in your application. For example, you might define a relationship between a user and a file to show that the user owns the file. In the context of an organization, you could define relationships that describe the relation a subject (like a user or a group of users) has with an object (like an organization or resources within the organization). For instance, you can create relationships in your Ory Network project using the Ory CLI. The relationships can showcase the namespace configuration and define a group with members and a folder hierarchy. Through the rules in the Ory Permission Language, every member of the group can access the files in the hierarchy. You can create additional fine-grained permission rules for certain objects. Here is an example of how to create these relationships in Ory Permissions:
Copy code
bash ory create relationships relationships.json      # Output:   # NAMESPACE OBJECT RELATION NAME SUBJECT   # Group developer members patrik   # Group developer members User:Patrik   # Group developer members User:Henning   # Folder keto/ viewers Group:developer#members   # File keto/README.md parents Folder:keto/   # Folder keto/src/ parents Folder:keto/   # File keto/src/main.go parents Folder:keto/src/   # File private owners User:Henning
In this example, the
developer
group has a relationship with the
keto/
folder, meaning that all members of the
developer
group can view the files in the
keto/
folder. For more information, you can refer to the [Ory Documentation](https://www.ory.sh/docs/keto/guides/simple-access-check-guide#understand-ory-permissions) and the [Ory CLI Documentation](https://www.ory.sh/docs/cli/ory-create#ory-create).
b
@chilly-king-10285 I'm referring specifically ory's concept of "organizations" in the context of SSO
c
A message from kapa.ai
In the context of Single Sign-On (SSO) and organizations, Ory allows you to group users within one project through organizations. An organization always belongs to one Ory project. Within a project, an identity can belong to an organization or remain without an organization. Organizations contain multiple OIDC SSO connections. All members of an organization must use one of the organization's OIDC SSO connections to log in. An organization can have multiple domains. Registrations for email addresses with a domain that belongs to an organization must go through one of the organization's OIDC SSO connections. After creating an organization, you can add one or more SSO OIDC connections. When a user enters an email that ends with the organization's domain on the registration page, a Sign in with SSO button appears instead of the password field. Clicking it will take the user to sign in with the SSO connection. The SSO connection is not visible for email addresses that are not managed by the organization. You can manage organizations using the Ory Console. To create, update, or delete organizations via the Ory Console, navigate to [Authentication > Organizations](https://console.ory.sh/projects/current/authentication/organizations). In terms of defining relationships, the concept of organizations in Ory doesn't directly provide a way to define relationships between different entities within the organization. The organization concept is more about grouping users and managing their authentication via SSO connections. For more details, you can refer to the [Ory Documentation](https://www.ory.sh/docs/kratos/organizations).
b
@chilly-king-10285 what do the "data mappings" do in the SSO configs
c
A message from kapa.ai
Data mappings in the Single Sign-On (SSO) configurations in Ory are used to map the data returned by the sign-in provider to traits as defined in the identity schema. This is necessary because every social sign-in provider returns different data in their payloads, and the payload isn't standardized. To define the mapping, you create a Jsonnet code snippet. This snippet becomes a part of the Ory Identities configuration for the given social sign-in provider. Here's an example of a Jsonnet snippet that maps the user's
email
to
email
in the identity schema:
Copy code
jsonnet local claims = std.extVar('claims');   {    identity: {    traits: {    // The email might be empty if the user hasn't granted permissions for the email scope.    [if 'email' in claims then 'email' else null]: claims.email,    },    },   }
In this example, if the
email
claim exists in the data returned by the sign-in provider, it is mapped to the
email
trait in the identity schema. If the
email
claim doesn't exist,
null
is assigned to the
email
trait. It's important to note that secrets such as API keys, credentials, or personal data should not be saved directly in Jsonnet code snippets. Jsonnet code snippets used for data mapping aren't stored in an encrypted format in Ory Network. For more information, you can refer to the [Ory Documentation](https://www.ory.sh/docs/kratos/social-signin/data-mapping).
b
@chilly-king-10285 which identity schema does it get mapped into? The default one?
c
A message from kapa.ai
Yes, the data from the SSO provider gets mapped into the default identity schema. The identity schema implements the JSON Schema Standard and allows you to adjust Ory specifically to your requirements. It specifies the types of data the system can store for users, such as their names, email addresses, phone numbers, and birthdays. When a new identity is created, the default schema is used to validate the identity data. If you use custom Identity Schemas, it can help to keep track of changes. You can copy the Identity Schema directly from the Ory Network console or get it from the config file you pulled earlier. Here is an example of how the default identity schema is defined in the configuration:
Copy code
json //...    # This is the default schema that's used for new identities    "default_schema_id": "<preset://email>",    # These are custom schemas that are available on your Ory Network project    "schemas": [    {    "id": "7d1cf71e-57ae-40be-bddf-1f4c323e2349",    "url": "<https://storage.googleapis.com/bac-gcs-production/something.schema.json>"    },    ],   //...
In this example, the default schema is set to "preset://email". This means that when a new identity is created, this schema will be used to validate the identity data. For more information, you can refer to the [Ory Documentation](https://www.ory.sh/docs/kratos/manage-identities/identity-schema).