ory / ory/network

Intercept OIDC linking / data mapping is not updated

Open
#292 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Shell
Stars
96
Forks
8
PR merge metrics
No merged PRs in 30d

Description

Preflight checklist
Describe the bug

For existing users, I want to reject OIDC account linking if the email domain does not match the email in the users traits. So for example, if I have a user like this:

identity:
  traits:
    name: 
        first: "John"
        last: "Doe"
    email: "john.doe@company.org"

I want to reject account linking if the user links with a Microsoft account with email john.doe@hotmail.com (the domain is different). I want to accept if it's john.doe@company.org or anyotheruser@company.org (domain OK).

Unfortunately, to my knowledge this is not possible at the moment. So one workaround I do now is to update the data mapping to include the email in the claims and put that in the public metadata, and then I can check the emails in retrospect. Something like this: if metadata_public.linked_email != traits.email: handle_bad_link().

So I go to https://console.ory.sh/projects/<project>/social-signin/microsoft and set up this data mapping:

local claims = std.extVar('claims');
{
    identity: {
        metadata_public: {
            linked_email: claims.email,
            foo: "bar"
        },
        traits: {
            email: claims.email,
            name: {
                "first": claims.family_name,
                [if "family_name" in claims then "last" else null]: claims.family_name,
            }            
        },
    },
}
What I expect

I expect when I link an account, the first name and last name will be the same. I also expect metadata_public to contain "foo" field and "linked_email" field.

What I get

I get that the first name and last name are different, and the metadata_public is not set.

Reproducing the bug
  1. set up microsoft linking with a "Common" tenant and the scopes outlined below.
  2. Have an existing account, and link that one
  3. Should have first name and last name same, and some data in public metadata. But it's not there
Relevant log output

No response

Relevant configuration
selfservice:
  methods:
    oidc:
      config:
        base_redirect_uri: [redacted]
        providers:
        - client_id: [redacted]
          client_secret: [redacted]
          id: microsoft
          label: Microsoft
          mapper_url: https://storage.googleapis.com/bac-gcs-production/a2fd16ac5b4671e74fd15ccda28b16e3e094a1f3aa5ba39cbf8880bfae3afef18ff3938df83813b03ffca19728526c11508e7ebf4ba03ff764648448db581c20.jsonnet
          microsoft_tenant: common
          provider: microsoft
          scope:
          - https://graph.microsoft.com/User.Read
          - profile
          - email
          - openid
          subject_source: me
      enabled: true
Version

ory network

On which operating system are you observing this issue?

Ory Network

In which environment are you deploying?

None

Additional Context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the existing-user Microsoft OIDC linking flow with the provided mapper configuration and compare the resulting traits and public metadata with the expected values. Done means the mapper preserves the expected first and last names and sets both metadata_public.foo and metadata_public.linked_email during account linking.

Written by the indexing model from the issue text.

Assessment

Domain
authentication
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.