Skip to content

Commit 48d2b84

Browse files
authored
docs: claims mapping debug tips and move old oidc troubleshooting doc (#2122)
docs: claims mapping debug + move old oidc troubleshooting doc
1 parent 7b72e92 commit 48d2b84

File tree

3 files changed

+87
-71
lines changed

3 files changed

+87
-71
lines changed

docs/troubleshooting/01_oidc-redirect-url-cname.mdx

Lines changed: 0 additions & 42 deletions
This file was deleted.

docs/troubleshooting/25_social-sign-in.mdx

Lines changed: 83 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,63 @@ sidebar_label: Social sign-in troubleshooting
66

77
# Social sign-in troubleshooting
88

9-
## 'redirect_uri' mismatch
9+
## Redirect loops after registration
1010

11-
Ensure that the `redirect_uri` query parameter in the URL matches the authorized redirect URI added to the social sign-in
12-
provider.
11+
Ory redirects users back to the registration page after a successful OIDC flow when some identity traits, for example a phone
12+
number, couldn't be mapped using the data received from the social sign-in provider and require manual input from the user.
1313

14-
```
15-
https://{provider}/o/oauth2/v2/auth?client_id=(...)&
16-
redirect_uri=https://$PROJECT_SLUG.projects.oryapis.com/self-service/methods/oidc/callback/{provider}&
17-
response_type=code&scope=email+profile+openid
18-
```
14+
However, when the Jsonnet configuration for the social sign-in provider is incorrect and Ory can't map the data correctly, the
15+
user sees no input fields and the registration page gets stuck in a redirect loop.
16+
17+
To understand how to fix the problem, let's look at how Ory handles the OIDC registration flow. There are 5 steps that the system
18+
performs when users register with a social sign-in provider:
1919

20-
:::info
20+
1. Redirect to the social sign-in provider.
21+
2. Redirect back to Ory with a `code` query parameter.
22+
3. Ory exchanges the `code` for an access token and retrieves the user information.
23+
4. Ory maps the user information to the [Identity Schema traits](../kratos/manage-identities/identity-schema).
24+
5. (optional) Ory redirects back to the registration page, requiring the user to provide the values for the missing traits.
2125

22-
If you get a `redirect_uri` mismatch error in a project created before September 2022 that uses a custom domain,
23-
[refer to this document](./oidc-redirect-url-cname-OTA-092022-01) for troubleshooting information.
26+
When step 4 fails, Ory becomes stuck in a redirect loop. To fix the redirect loop, adjust the Jsonnet configuration for the social
27+
sign-in provider so that the data from the provider gets mapped correctly to the Identity Schema. Read
28+
[Map and merge profile data](../kratos/social-signin/data-mapping) to learn more.
29+
30+
### Debug Jsonnet claims mapping
31+
32+
When the registration flow gets stuck in a redirect loop, it's often because the Jsonnet snippet fails to map the incoming claims
33+
from the social sign-in provider to your Identity Schema traits. To debug this, it can help to see the actual claims data Ory
34+
receives from the provider and how it's structured.
35+
36+
1. To ensure the registration process can complete simplify the `identity.traits` section in your Jsonnet, perhaps only mapping
37+
one non-essential field or even leaving it empty `{}`.
38+
2. To capture the full claims object add a field to `identity.metadata_public`. Or `identity.metadata_admin` if the claims contain
39+
sensitive data you don't want exposed to the user.
40+
41+
Here's an example of a minimal Jsonnet configuration for debugging purposes:
42+
43+
```jsonnet
44+
local claims = std.extVar('claims');
45+
{
46+
identity: {
47+
traits: {
48+
// Minimal traits mapping - adjust as needed
49+
[if 'email' in claims && claims.email_verified then 'email' else null]: claims.email,
50+
// You might even use traits: {} temporarily if no traits are strictly required
51+
},
52+
metadata_public: {
53+
// Store all received claims
54+
debug_claims: claims
55+
}
56+
},
57+
}
58+
```
2459

25-
:::
60+
1. Apply temporary Jsonnet configuration to your social sign-in provider settings.
61+
2. Attempt the registration flow again with the social provider. The registration should now succeed.
62+
3. Inspect the identity created in Ory. You can use the Ory Console, Ory CLI, or the API.
63+
4. Analyze the `debug_claims`. This shows what data your Jsonnet has access to via the claims variable.
64+
5. Fix your original Jsonnet traits mapping logic so it references only available claims.
65+
6. Once your primary Jsonnet mapping is fixed, remove the temporary `debug_claims` field from the metadata.
2666

2767
## 'oryapis.com' doesn't work as authorized redirect URI
2868

@@ -42,28 +82,42 @@ Ensure that the custom domain is added to the social sign-in provider as an auth
4282

4383
:::
4484

45-
## Redirect loops after successful registration
85+
## 'redirect_uri' mismatch
4686

47-
Ory redirects users back to the registration page after a successful OIDC flow when some identity traits, for example a phone
48-
number, couldn't be mapped using the data received from the social sign-in provider and require manual input from the user.
87+
Ensure that the `redirect_uri` query parameter in the URL matches the authorized redirect URI added to the social sign-in
88+
provider.
4989

50-
However, when the Jsonnet configuration for the social sign-in provider is incorrect and Ory can't map the data correctly, the
51-
user sees no input fields and the registration page gets stuck in a redirect loop.
90+
```
91+
https://{provider}/o/oauth2/v2/auth?client_id=(...)&
92+
redirect_uri=https://$PROJECT_SLUG.projects.oryapis.com/self-service/methods/oidc/callback/{provider}&
93+
response_type=code&scope=email+profile+openid
94+
```
5295

53-
To understand how to fix the problem, let's look at how Ory handles the OIDC registration flow. There are 5 steps that the system
54-
performs when users register with a social sign-in provider:
96+
### Social sign-in `redirect_uri_mismatch` error (OTA-092022-01)
5597

56-
1. Redirect to the social sign-in provider.
57-
2. Redirect back to Ory with a `code` query parameter.
58-
3. Ory exchanges the `code` for an access token and retrieves the user information.
59-
4. Ory maps the user information to the [Identity Schema traits](../kratos/manage-identities/identity-schema).
60-
5. (optional) Ory redirects back to the registration page, requiring the user to provide the values for the missing traits.
98+
This affects only projects created before September 2022 that use a custom domain. For newly added social sign-in providers,
99+
social sign-in flows can fail with the following message:
61100

62-
When step 4 fails, Ory becomes stuck in a redirect loop. To fix the redirect loop, adjust the Jsonnet configuration for the social
63-
sign-in provider so that the data from the provider gets mapped correctly to the Identity Schema.
101+
```text
102+
Unable to complete OpenID Connect flow because the OpenID Provider returned error "redirect_uri_mismatch": The redirect_uri MUST match the registered callback URL for this application.
103+
```
64104

65-
:::tip
105+
#### Mitigation OTA-092022-01
66106

67-
Read [Map and merge profile data](../kratos/social-signin/data-mapping) to learn more.
107+
To fix the problem, remove the `/selfservice/methods/oidc/config/base_redirect_uri` configuration entry. Run this Ory CLI command:
68108

69-
:::
109+
```shell
110+
## List all available workspaces
111+
ory list workspaces
112+
113+
## List all available projects
114+
ory list projects --workspace <workspace-id>
115+
116+
## Remove the configuration entry
117+
ory patch identity-config <project-id> \
118+
--remove '/selfservice/methods/oidc/config/base_redirect_uri'
119+
```
120+
121+
Removing the `base_redirect_uri` can break previously existing and functional social sign-in connections. To fix a broken
122+
connection, choose the provider you want to fix from the <ConsoleLink route="project.socialSignIn" /> section and copy the
123+
redirect URI. Use the value you copied to update the callback URL configuration of the social sign-in provider.

vercel.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,10 @@
11921192
{
11931193
"source": "/docs/guides/master/oathkeeper/1-overview/1-rules",
11941194
"destination": "/docs/oathkeeper/api-access-rules"
1195+
},
1196+
{
1197+
"source": "/docs/troubleshooting/oidc-redirect-url-cname-OTA-092022-01",
1198+
"destination": "/docs/troubleshooting/troubleshooting-social-sign-in"
11951199
}
11961200
]
11971201
}

0 commit comments

Comments
 (0)