stocky-lion-92458
01/28/2025, 3:28 PM{
"amr": [
"oidc"
],
"aud": [
"ce7fd896-ee73-4785-b5f1-4aebfdc1a1c9"
],
"auth_time": 1637735144,
"iat": 1618069753,
"iss": "<https://somedomain.com>",
"rat": 1738069749,
"sub": "7e4de2r7-c700-4c7f-be34-3b5d02tay116"
}
the custom identity schema template is
{
"$id": "<https://schemas.ory.sh/presets/kratos/identity.blank.schema.json>",
"title": "SSO-V10",
"type": "object",
"properties": {
"traits": {
"type": "object",
"properties": {
"email": {
"title": "Email",
"type": "string",
"format": "email",
"<http://ory.sh/kratos|ory.sh/kratos>": {
"credentials": {
"password": {
"identifier": true
}
}
}
},
"first_name": {
"title": "First Name",
"type": "string"
},
"last_name": {
"title": "Last Name",
"type": "string"
},
"phone_no": {
"type": "number",
"title": "Phone number"
},
"country_code": {
"type": "string",
"title": "Country Code"
},
"company": {
"type": "object",
"properties": {
"company_name": {
"type": "string",
"title": "Company Name"
},
"company_address": {
"type": "object",
"properties": {
"address_line_1": {
"type": "string",
"title": "Address Line 1"
},
"address_line_2": {
"type": "string",
"title": "Address Line 2"
},
"city": {
"type": "string",
"title": "City"
},
"state": {
"type": "string",
"title": "State/Province"
},
"country": {
"type": "string",
"title": "Country"
},
"zip_code": {
"type": "string",
"title": "Zip Code"
}
},
"required": []
}
},
"required": []
}
},
"required": [
"email"
],
"additionalProperties": true
}
},
"$schema": "<http://json-schema.org/draft-07/schema#>"
}
,I'm using SSO provider as google OIDC
Data Mapping:
local claims = {
email_verified: true,
} + std.extVar('claims');
{
identity: {
traits: {
-- Check if email exists and if it's verified, then map it to 'email'
email: if 'email' in claims && claims.email_verified then claims.email else null,
-- Map other claims as required
first_name: claims.given_name,
last_name: claims.family_name,
},
},
}
scopes:
email ,openid,profile
brief-egg-61061
01/28/2025, 3:28 PMbrief-egg-61061
01/28/2025, 3:28 PMemail
and profile
scopes. As mentioned in the [Ory Hydra API discussion](https://github.com/ory/hydra/discussions/3799), this could be a reason for missing claims. 2. Verify that the user agent (your application) is actually requesting these scopes during the authentication process. 3. Make sure the user is consenting to these scopes during the authorization process. 4. Check if the email
scope is being properly processed and included in the access token. You can decode the access token to see what claims are included. 5. Ensure that your Ory Hydra configuration is set up to include these claims in the userinfo endpoint response. This might involve checking your Hydra configuration and potentially using [OAuth2 webhooks](https://www.ory.sh/docs/oauth2-oidc/openid-connect-claims-scope-custom) to customize the claims included in your tokens. 6. Verify that the email verification status is being properly carried over from the OIDC provider (Google in this case). There was a known issue with this in the past, as mentioned in a [GitHub issue discussion](https://github.com/ory/network/issues/246). If you've checked all of these and are still having issues, you might want to: 1. Double-check your Ory Hydra and Kratos configurations to ensure they're set up correctly for handling these scopes and claims. 2. Verify that your Google OIDC provider configuration is correct and is set to provide the email claim. 3. Consider using the Ory CLI to inspect your configuration and potentially set additional options for claim handling. If the problem persists after checking these points, you may want to reach out to Ory support or post in the Ory Community Slack for more specific assistance, as the issue might be related to your particular setup or a potential bug in the system.stocky-lion-92458
01/28/2025, 3:50 PMstocky-lion-92458
01/28/2025, 3:52 PMbrief-egg-61061
01/28/2025, 3:52 PMbrief-egg-61061
01/28/2025, 3:52 PMstocky-lion-92458
01/28/2025, 3:54 PMbrief-egg-61061
01/28/2025, 3:55 PMbrief-egg-61061
01/28/2025, 3:56 PMjavascript
export async function acceptConsent(consentChallenge: string) {
const { data } = await ory.getOAuth2ConsentRequest({ consentChallenge })
return await ory
.acceptOAuth2ConsentRequest({
consentChallenge: consentChallenge,
acceptOAuth2ConsentRequest: {
session: {
id_token: {
email: "<mailto:user@example.com|user@example.com>", // Replace with actual email
},
},
},
})
.then(({ data }) => data)
}
5. Google OIDC Provider Specifics:
There's a specific issue mentioned in the [Ory Network GitHub](https://github.com/ory/network/issues/242) about Google's OIDC provider. Google doesn't support the "offline_access" scope directly. Instead, it uses the parameter access_type=offline
. Make sure your configuration for the Google provider is set up correctly:
yaml
oidc:
config:
providers:
- client_id: xxxx
client_secret: xxx
id: google
label: Google
mapper_url: xxx
provider: google
scope:
- email
- profile
- <https://www.googleapis.com/auth/gmail.compose>
- <https://www.googleapis.com/auth/gmail.readonly>
And ensure that the access_type=offline
is being added to the auth URL when necessary.brief-egg-61061
01/28/2025, 3:56 PMjavascript export async function acceptConsent(consentChallenge: string) { const { data } = await ory.getOAuth2ConsentRequest({ consentChallenge }) return await ory .acceptOAuth2ConsentRequest({ consentChallenge: consentChallenge, acceptOAuth2ConsentRequest: { session: { id_token: { email: "<mailto:user@example.com|user@example.com>", // Replace with actual email }, }, }, }) .then(({ data }) => data) }
5. Google OIDC Provider Specifics: There's a specific issue mentioned in the [Ory Network GitHub](https://github.com/ory/network/issues/242) about Google's OIDC provider. Google doesn't support the "offline_access" scope directly. Instead, it uses the parameter access_type=offline
. Make sure your configuration for the Google provider is set up correctly: yaml oidc: config: providers: - client_id: xxxx client_secret: xxx id: google label: Google mapper_url: xxx provider: google scope: - email - profile - <https://www.googleapis.com/auth/gmail.compose> - <https://www.googleapis.com/auth/gmail.readonly>
And ensure that the access_type=offline
is being added to the auth URL when necessary. If after checking these additional points you're still experiencing the same issue, I would strongly recommend reaching out to Ory support directly or posting in the Ory Community Slack. The problem might be specific to your environment or could potentially be a bug that needs to be addressed by the Ory team.stocky-lion-92458
01/28/2025, 4:08 PMbrief-egg-61061
01/28/2025, 4:08 PMbrief-egg-61061
01/28/2025, 4:09 PMemail
scope is being properly processed. As mentioned in the [Ory documentation on customizing OpenID Connect scopes and claims](https://www.ory.sh/docs/oauth2-oidc/openid-connect-claims-scope-custom), the system uses the verifiable addresses of a user for the email
scope. Ensure that your user has a verified email address in their Ory Identities profile. 3. Check Verifiable Addresses: In your Ory Identities configuration, make sure that the user's email is listed under verifiable addresses and is marked as verified. 4. Implement a Custom Consent Endpoint: As suggested in a [GitHub comment](https://github.com/ory/network/issues/267#issuecomment-1465958644), you might want to consider implementing a custom consent endpoint. This would give you full control over what data goes into your tokens and the userinfo response. 5. Use OAuth2 Webhooks: As mentioned in the [Ory documentation](https://www.ory.sh/docs/oauth2-oidc/openid-connect-claims-scope-custom), you can use OAuth2 webhooks to add custom claims to your tokens for different OAuth flows. This might be a way to ensure the email claim is included. If none of these solutions work, it's possible that you're encountering a bug or a configuration issue that's specific to your setup. In this case, I strongly recommend reaching out to Ory support directly with detailed information about your setup, including: - Your complete OAuth2 and OpenID Connect configuration - The exact flow you're using to authenticate - The full response you're getting from the userinfo endpoint - Any error messages or logs you're seeing They will be able to provide more specific assistance based on your exact configuration and environment.stocky-lion-92458
01/28/2025, 4:12 PMbrief-egg-61061
01/28/2025, 4:12 PMbrief-egg-61061
01/28/2025, 4:13 PMemail
scope is being properly requested and consented to during the authentication process. 2. Data Mapping: Review your data mapping configuration. According to your previous message, you're using a Jsonnet snippet for mapping. Ensure that this mapping is correctly implemented and that it's being applied during the authentication process. You might want to log the claims received from the Google OIDC provider to ensure the email is being passed correctly. 3. Identity Schema: Your identity schema includes an email field, which is correct. However, make sure that the email is actually being populated in the identity when it's created or updated through the OIDC flow. 4. OAuth2 Token Hook: As described in a [GitHub issue about email claims](https://github.com/ory/hydra/issues/3879), you might want to implement an OAuth2 token hook. This hook can be used to add or modify claims in the tokens. Here's an example of how you might set this up: ory patch oauth2-config --project PROJECT --workspace WORKSPACE \ --add '/oauth2/token_hook/url="<https://TUNNEL/claims>"' \ --add '/oauth2/token_hook/auth/type="api_key"' \ --add '/oauth2/token_hook/auth/config/in="header"' \ --add '/oauth2/token_hook/auth/config/name="X-API-Key"' \ --add '/oauth2/token_hook/auth/config/value="SOME_API_KEY"' \ --format yaml
Then, in your webhook handler, you can explicitly add the email claim to the token. 5. Google OIDC Provider Configuration: Ensure that your Google OIDC provider is correctly configured to provide the email claim. Check the scopes you're requesting and make sure they include email
. 6. Debugging: Enable debug logging in your Ory setup to get more detailed information about the authentication process. This might help identify where the email claim is being lost or not included. If after checking these points you're still not seeing the email claim in either the ID token or the userinfo endpoint, it's likely that you're encountering a bug or a configuration issue specific to your setup. In this case, I strongly recommend reaching out to Ory support directly with detailed logs and configuration information. They will be able to provide more specific assistance based on your exact setup and environment.stocky-lion-92458
01/28/2025, 4:19 PMbrief-egg-61061
01/28/2025, 4:19 PMbrief-egg-61061
01/28/2025, 4:19 PMexport LOG_LEVEL=debug
Or in your configuration file (e.g., kratos.yml
or hydra.yml
): yaml log: level: debug format: json
2. The debug
log level provides very verbose logging. If you need even more detailed information, you can use the trace
level, which includes call traces of errors and log calls. 3. You can also adjust the log format. The format
configuration key supports text
and json
. JSON format can be easier to parse programmatically: yaml log: level: debug format: json
4. Be cautious with sensitive data. There's a configuration option leak_sensitive_values
which should typically be set to `false`: yaml log: level: debug format: json leak_sensitive_values: false
5. Log output is sent to stdout/stderr by default. You can redirect this to a file using bash pipes if needed: hydra serve all >log.txt 2>&1
Remember, debug logging can generate a large volume of logs, so it's recommended to use it judiciously and only when needed for troubleshooting. For more detailed information on Ory logging configuration, you can refer to the [Ory documentation on logs and audit trails](https://www.ory.sh/docs/self-hosted/operations/logging).stocky-lion-92458
01/28/2025, 4:39 PMbrief-egg-61061
01/28/2025, 4:39 PMbrief-egg-61061
01/28/2025, 4:40 PMbrief-egg-61061
01/28/2025, 4:44 PMbrief-egg-61061
01/28/2025, 4:44 PM