bumpy-controller-43157
06/11/2025, 1:02 PMbrief-egg-61061
06/11/2025, 1:02 PMbrief-egg-61061
06/11/2025, 1:02 PMjsonnet local claims = std.extVar('claims'); { identity: { traits: { [if 'email' in claims then 'email' else null]: claims.email, }, metadata_public: { microsoft_tenant: claims.tid, // 'tid' is the tenant ID claim from Microsoft microsoft_identity_id: claims.sub, // 'sub' is the unique identifier for the user }, }, }
- claims.tid
stores the Microsoft tenant ID. - claims.sub
stores the unique identity ID from Microsoft. This approach is based on the documented method for mapping claims to traits and metadata in Ory Kratos, and follows the pattern for setting public metadata as shown in the [official documentation](https://www.ory.sh/docs/kratos/social-signin/data-mapping#write-a-jsonnet-data-mapper) and the [GitHub example](https://www.ory.sh/docs/kratos/social-signin/data-mapping#end-to-end-github-example). If your Azure AD setup uses a different claim for the tenant, adjust claims.tid
accordingly (for example, use claims.oid
if that's where your tenant is stored). Note: The knowledge sources confirm that you can set public metadata fields in the data mapper, and that claims such as sub
and tenant information are available in the claims object provided by Microsoft OIDC responses. If you need to map a different claim, inspect the actual claims returned by your Microsoft OIDC provider and adjust the keys as needed. References: - [Write a Jsonnet data mapper](https://www.ory.sh/docs/kratos/social-signin/data-mapping#write-a-jsonnet-data-mapper) - [End-to-end GitHub example](https://www.ory.sh/docs/kratos/social-signin/data-mapping#end-to-end-github-example)bumpy-controller-43157
06/11/2025, 1:23 PMbrief-egg-61061
06/11/2025, 1:24 PMbrief-egg-61061
06/11/2025, 1:24 PMclient_secret: ....
for each provider. This value can be templated or injected by your pipeline tool when generating the configuration file before applying it to Ory: yaml selfservice: methods: oidc: config: providers: - id: microsoft provider: microsoft client_id: .... # Injected by your pipeline client_secret: .... # Injected by your pipeline # ...
- Environment variables: While not recommended for complex objects, you can set the full JSON array of providers as an environment variable if needed, as shown in the docs: bash export SELFSERVICE_METHODS_OIDC_CONFIG_PROVIDERS='[{"id":"google","provider":"google","mapper_url":"<file_location>","client_id":"<client_id>","client_secret":"<client_secret>","scope":["openid","email","profile"],"auth_url":"<https://accounts.google.com/o/oauth2/v2/auth>","token_url":"<https://www.googleapis.com/oauth2/v4/token>","issuer_url":"<https://accounts.google.com>"}]'
But this approach is only recommended if you are comfortable with the syntax and complexity involved. Summary: Inject the client secrets at the configuration level (YAML or environment variable) in your pipeline, not in the Jsonnet data mapping. Use your pipeline's secret management capabilities to substitute the secret values before applying the configuration to Ory Kratos or Ory Network. Do not put secrets in Jsonnet code snippets, as they are not encrypted or protected in that context. For more details, see the section on [OIDC provider configuration and environment variables](https://www.ory.sh/docs/self-hosted/kratos/configuration/oidc) in the documentation.bumpy-controller-43157
06/11/2025, 1:25 PMbumpy-controller-43157
06/11/2025, 1:25 PMbrief-egg-61061
06/11/2025, 1:25 PMbrief-egg-61061
06/11/2025, 1:25 PMbumpy-controller-43157
06/11/2025, 1:38 PMbrief-egg-61061
06/11/2025, 1:38 PMbrief-egg-61061
06/11/2025, 1:38 PMjsonnet local claims = { email_verified: false } + std.extVar('claims'); { identity: { traits: { [if 'email' in claims && claims.email_verified then 'email' else null]: claims.email, }, }, }
If the OIDC provider does not return a verified email, the traits.email
field will be missing. Since your identity schema requires this field, Ory will return a validation error and will not create the identity or trigger manual verification. This approach is explicitly recommended in the documentation to prevent account enumeration and other attack vectors related to unverified emails from social sign-in providers [Write a Jsonnet data mapper](https://www.ory.sh/docs/kratos/social-signin/data-mapping#emails-and-phone-numbers). Summary: - Require traits.email
in your identity schema. - Use a Jsonnet data mapper that only sets traits.email
if the email is present and verified. - If the email is not verified, registration fails and no identity is created. This ensures that only users with a verified email from the OIDC provider can register, and no manual verification is triggered.