<@U04UQ68083H> in Ory Network: Assuming a user has...
# ory-copilot
l
@chilly-king-10285 in Ory Network: Assuming a user has registered with a password and now uses Social Sign In the next time they log in. How do I get the information provided by the social sign in provider, such as first name and surname, so that it is also saved on the profile of the already registered user?
b
A message from kapa.ai
To address your question about updating an existing user's profile with information from a social sign-in provider in Ory Network, you can use the automatic account linking feature along with a custom data mapping. Here's how you can achieve this: 1. Enable automatic account linking: Ory Network supports automatic account linking, which allows users to link their social sign-in accounts to their existing password-based accounts. This feature is described in the [User account linking documentation](https://www.ory.sh/docs/kratos/social-signin/link-multiple-provider-account#automatic-account-linking). 2. Create a custom data mapping: To save the information provided by the social sign-in provider (such as first name and surname) to the existing user's profile, you need to create a custom data mapping using Jsonnet. Here's an example of how you can do this:
Copy code
jsonnet local claims = {   email_verified: false, } + std.extVar('claims');  {   identity: {     traits: {       [if 'email' in claims && claims.email_verified then 'email' else null]: claims.email,       first_name: claims.given_name,       last_name: claims.family_name,     },   }, }
3. Configure the social sign-in provider: Add the custom data mapping to your social sign-in provider configuration. You can do this either through the Ory Console or using the Ory CLI. Here's an example of how to configure it using the CLI:
Copy code
yaml selfservice:   methods:     oidc:       config:         providers:           - id: your_provider_id             provider: generic             client_id: your_client_id             client_secret: your_client_secret             issuer_url: <https://your_provider_issuer_url>             mapper_url: "base64://{YOUR_BASE64_ENCODED_JSONNET_HERE}"             scope:               - email               - profile             claims_source: id_token       enabled: true
By following these steps, when a user who has previously registered with a password uses social sign-in, the automatic account linking process will occur. The custom data mapping will then update the user's profile with the information provided by the social sign-in provider, such as first name and surname. Remember to adjust the data mapping according to your specific identity schema and the claims provided by your social sign-in provider. Also, ensure that your identity schema includes the fields you want to update (e.g.,
first_name
and
last_name
). For more detailed information on configuring social sign-in and data mapping, you can refer to the following documentation: - [Map and merge profile data](https://www.ory.sh/docs/kratos/social-signin/data-mapping) - [Generic provider configuration](https://www.ory.sh/docs/kratos/social-signin/generic)