faint-bear-71759
12/11/2024, 9:51 AMbrief-egg-61061
12/11/2024, 9:51 AMbrief-egg-61061
12/11/2024, 9:52 AMfaint-bear-71759
12/11/2024, 9:52 AMbrief-egg-61061
12/11/2024, 9:53 AMbrief-egg-61061
12/11/2024, 9:53 AMkratos.yml
), add the following: yaml selfservice: flows: registration: after: password: hooks: - hook: session oidc: hooks: - hook: session
This configuration tells Kratos to create a session after successful registration, both for password-based and OIDC (social sign-in) methods. 2. It's particularly important to add the "session" hook for the OIDC flow, as mentioned in the [Ory documentation](https://www.ory.sh/docs/kratos/self-service/flows/user-registration#successful-registration): "It's very important to add the "session" hook to the after oidc
registration hooks. Otherwise your users need to use the login flow again to be able to get a session." By adding this configuration, users should be automatically logged in after registering through social sign-in. If you're using Ory Network (the cloud offering) instead of self-hosted Kratos, you might need to configure this through the Ory Console or CLI, as direct access to the configuration file might not be available. [Ory Kratos Registration Flow Documentation](https://www.ory.sh/docs/kratos/self-service/flows/user-registration#successful-registration) If you've already made this configuration change and are still experiencing issues, there might be other factors at play, and you may need to investigate further or reach out to Ory support for more specific assistance.faint-bear-71759
12/11/2024, 10:15 AMbrief-egg-61061
12/11/2024, 10:15 AMbrief-egg-61061
12/11/2024, 10:16 AMyaml selfservice: methods: password: enabled: true oidc: enabled: true flows: registration: after: password: hooks: []
By removing the hooks for the password method in the registration flow, you effectively disable password-based registration. 2. Next, ensure that the OIDC method is enabled for registration: yaml selfservice: flows: registration: after: oidc: hooks: - hook: session
This configuration enables OIDC-based registration and ensures that users get a session after registering through a social sign-in provider. 3. To allow only admins to create password identities, you would need to use the Ory Identities API to programmatically create identities. This can be done through your admin interface or backend service. The API endpoint for creating identities is described in the [Ory Identities API documentation](https://www.ory.sh/docs/reference/api#tag/identity/operation/createIdentity). By implementing these configurations, you achieve the following: - Users can only register through OIDC (social sign-in) methods. - Password-based registration is disabled for regular users. - Only admins (or your backend services) can create password-based identities using the Ory Identities API. Remember to adjust these configurations based on your specific Ory setup (Ory Network or self-hosted Kratos) and ensure that your admin interface or backend service has the necessary permissions to create identities via the API. [Ory Kratos Configuration](https://www.ory.sh/docs/kratos/reference/configuration) [Ory Identities API](https://www.ory.sh/docs/reference/api#tag/identity/operation/createIdentity)faint-bear-71759
12/11/2024, 12:18 PMbrief-egg-61061
12/11/2024, 12:18 PMbrief-egg-61061
12/11/2024, 12:18 PMPOST /admin/identities
endpoint. Here's how you can structure your request: 1. First, you need to include the OIDC credentials in the identity creation payload. The structure for OIDC credentials is as follows: json { "credentials": { "oidc": { "config": { "providers": [ { "subject": "some-user", "provider": "google", "initial_access_token": "********************", "initial_refresh_token": "********************", "initial_id_token": "********************" } ] } } } }
2. You would include this in your full identity creation payload, along with other required fields such as schema_id
and traits
. Here's an example of how the full payload might look: json { "schema_id": "default", "traits": { "email": "<mailto:user@example.com|user@example.com>" }, "credentials": { "oidc": { "config": { "providers": [ { "subject": "some-user", "provider": "google", "initial_access_token": "********************", "initial_refresh_token": "********************", "initial_id_token": "********************" } ] } } } }
3. Send this payload to the /admin/identities
endpoint using a POST request. It's important to note that the exact structure of the traits
object will depend on your identity schema configuration. This method of creating OIDC identities is particularly useful when you need to import existing users from another system or when you're performing administrative tasks that require creating identities with pre-existing OIDC credentials. Remember to handle the tokens securely, as they provide access to user accounts. Also, ensure that your application has the necessary permissions to create identities via the API. [Ory Identities API - Create Identity](https://www.ory.sh/docs/reference/api#tag/identity/operation/createIdentity) [Ory Kratos - Get Social Sign-in Provider Tokens](https://www.ory.sh/docs/kratos/social-signin/get-tokens)