billions-elephant-38030
05/10/2024, 10:25 PMchilly-king-10285
05/10/2024, 10:25 PMchilly-king-10285
05/10/2024, 10:25 PM<http://127.0.0.1/sessions/whoami>
endpoint with the session token or cookie. The response will include the identity
object, which contains the verifiable_addresses
array. Each item in this array represents a verifiable address and includes a verified
field that indicates whether the address has been verified. Here is an example of how to check the session information: bash curl -s -H "Authorization: Bearer svX8bE9HTiVpMr7r55TtKtcOkLRhAq1a" \ <https://playground.projects.oryapis.com/sessions/whoami> | jq
In the response, you can check the verified
field for each item in the verifiable_addresses
array: json "verifiable_addresses": [ { "id": "3ba119c6-4e9a-466c-8910-40b238229aa6", "value": "[[email protected]](<https://www.ory.sh/cdn-cgi/l/email-protection>)", "verified": false, "via": "email", "status": "pending", "verified_at": null } ]
In this example, the verified
field is false
, which means the address has not been verified. Please note that this process does not happen automatically in Oathkeeper and would need to be implemented in your application logic. Sources: - [Kratos User Login](https://www.ory.sh/docs/kratos/self-service/flows/user-login#api-clients) - [Oathkeeper Authenticators](https://www.ory.sh/docs/oathkeeper/pipeline/authn#cookie_session-configuration)billions-elephant-38030
05/10/2024, 10:27 PMchilly-king-10285
05/10/2024, 10:27 PMchilly-king-10285
05/10/2024, 10:28 PMAuthorization
header. 2. Use this session token to make a request to the Kratos /sessions/whoami
endpoint. This will return the session information, including the user's identity and the status of their verifiable addresses. Here's an example of how to make this request using `curl`: bash curl -s -H "Authorization: Bearer {session_token}" \ <https://playground.projects.oryapis.com/sessions/whoami> | jq
Replace {session_token}
with the actual session token. 3. In the response, look for the verifiable_addresses
array in the identity
object. Each item in this array represents a verifiable address and includes a verified
field that indicates whether the address has been verified. Here's an example of what this part of the response might look like: json "verifiable_addresses": [ { "id": "3ba119c6-4e9a-466c-8910-40b238229aa6", "value": "[[email protected]]", "verified": false, "via": "email", "status": "pending", "verified_at": null } ]
In this example, the verified
field is false
, which means the address has not been verified. 4. Based on the verified
field, you can then implement your own logic to handle the request depending on whether the user has verified their addresses. Please note that this process does not happen automatically in Ory Oathkeeper and would need to be implemented in your application logic. Sources: - [Kratos User Login](https://www.ory.sh/docs/kratos/self-service/flows/user-login#api-clients) - [Oathkeeper Authenticators](https://www.ory.sh/docs/oathkeeper/pipeline/authn#cookie_session-configuration)billions-elephant-38030
05/10/2024, 10:29 PMchilly-king-10285
05/10/2024, 10:29 PMchilly-king-10285
05/10/2024, 10:29 PMX-User
header to your backend, it means that a mutator is configured to add this header. The X-User
header typically contains the user's ID or some other identifier. However, Oathkeeper itself does not provide detailed user information such as the verification status of user addresses. To get this information, your backend will need to make an additional request to Ory Kratos using the session token. Here's how you can do this: 1. Extract the session token from the Authorization
header of the incoming request. 2. Use this session token to make a request to the Kratos /sessions/whoami
endpoint. This will return the session information, including the user's identity and the status of their verifiable addresses. Here's an example of how to make this request using `curl`: bash curl -s -H "Authorization: Bearer {{session_token}}" \ <https://playground.projects.oryapis.com/sessions/whoami> | jq
Replace {{session_token}}
with the actual session token. 3. In the response, look for the verifiable_addresses
array in the identity
object. Each item in this array represents a verifiable address and includes a verified
field that indicates whether the address has been verified. Here's an example of what this part of the response might look like: json "verifiable_addresses": [ {{ "id": "3ba119c6-4e9a-466c-8910-40b238229aa6", "value": "[[email protected]]", "verified": false, "via": "email", "status": "pending", "verified_at": null }} ]
In this example, the verified
field is false
, which means the address has not been verified. 4. Based on the verified
field, you can then implement your own logic to handle the request depending on whether the user has verified their addresses. Please note that this process does not happen automatically in Ory Oathkeeper and would need to be implemented in your application logic. Sources: - [Kratos User Login](https://www.ory.sh/docs/kratos/self-service/flows/user-login#api-clients) - [Oathkeeper Authenticators](https://www.ory.sh/docs/oathkeeper/pipeline/authn#cookie_session-configuration)faint-helmet-53309
05/12/2024, 4:12 PMX-Verified-Email: |
{{- $all := len .Extra.identity.verifiable_addresses -}}
{{- $verified := 0 -}}
{{- range .Extra.identity.verifiable_addresses}}{{ if .verified }}{{ $verified = add $verified 1}}{{end}}{{end -}}
{{- eq $verified $all -}}
Maybe it helps as a starting pointbillions-elephant-38030
05/22/2024, 9:11 AMif (request.headers["x-user"]?.length) {
await identityApi
.getIdentity({
id: request.headers["x-user"],
})
.then((resp: any) => {
const identity: Identity = resp.data;
identity?.verifiable_addresses?.every(
(verifiable_address) => verifiable_address.verified
)
? Promise.resolve
: reply.code(403).send("User must verify their email or phone");
});
} else {
reply.code(400).send("Missing required header");
}
billions-elephant-38030
05/22/2024, 9:11 AMfaint-helmet-53309
05/22/2024, 10:12 AMbillions-elephant-38030
05/22/2024, 11:19 AM