rapid-river-3747
01/20/2025, 3:32 AMbrief-egg-61061
01/20/2025, 3:32 AMbrief-egg-61061
01/20/2025, 3:32 AMlistIdentities
endpoint with a specific query parameter. Here's how you can do it: 1. Use the listIdentities
endpoint: GET /admin/identities
2. Include the credentials_identifier
query parameter with the email address you want to look up. Here's an example of how the API call would look: GET /admin/identities?credentials_identifier=user@example.com
This approach is described in the [Ory API Reference](https://www.ory.sh/docs/reference/api). The credentials_identifier
parameter is used for looking up identities by their identifier, which can be an email address if it's configured as an identifier in your identity schema. It's important to note that this method will only work if the email is set as an identifier in your identity schema. You can configure this in your schema by adding the following to the email field: json "<http://ory.sh/kratos|ory.sh/kratos>": { "credentials": { "password": { "identifier": true } } }
Remember that this method returns a list of identities, so you may need to handle cases where multiple identities are returned (though typically, email addresses are unique). For more detailed information on identity schemas and how to configure identifiers, you can refer to the [Ory Kratos Identity Schema Documentation](https://www.ory.sh/docs/kratos/manage-identities/identity-schema).rapid-river-3747
01/20/2025, 9:05 AMbrief-egg-61061
01/20/2025, 9:05 AMbrief-egg-61061
01/20/2025, 9:05 AM<http://github.com/ory/kratos-client-go|github.com/ory/kratos-client-go>
package: go package main import ( "context" "fmt" "os" ory "<http://github.com/ory/kratos-client-go|github.com/ory/kratos-client-go>" ) func main() { configuration := ory.NewConfiguration() configuration.Servers = []ory.ServerConfiguration{ { URL: "<http://127.0.0.1:4434>", // Kratos Admin API }, } apiClient := ory.NewAPIClient(configuration) // Replace with the email you want to search for email := "<mailto:user@example.com|user@example.com>" // List identities with the email as the credentials identifier identities, r, err := apiClient.IdentityApi.ListIdentities(context.Background()).CredentialsIdentifier(email).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `IdentityApi.ListIdentities`: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) return } // Check if any identities were found if len(identities) > 0 { fmt.Printf("Found identity with ID: %s\n", identities[0].Id) fmt.Printf("Email: %v\n", identities[0].Traits["email"]) } else { fmt.Println("No identity found with the given email.") } }
This example uses the ListIdentities
method from the IdentityApi
in the Kratos Go SDK. It sets the CredentialsIdentifier
parameter to the email address you're searching for. A few important points to note: 1. Make sure to replace the URL in configuration.Servers
with your actual Kratos Admin API URL. 2. The email address must be set as an identifier in your identity schema for this to work, as mentioned in the [Identity schema extensions documentation](https://www.ory.sh/docs/kratos/manage-identities/customize-identity-schema#password-login-identifier). 3. This method returns a list of identities. In most cases, you'll get only one result for a unique email, but you should handle cases where multiple or no identities are returned. 4. Remember to handle errors and the HTTP response appropriately in your production code. For more detailed information on using the Kratos Go SDK, you can refer to the [Ory Identity Management Go SDK documentation](https://www.ory.sh/docs/kratos/sdk/go).rapid-river-3747
01/20/2025, 9:17 AMbrief-egg-61061
01/20/2025, 9:17 AMbrief-egg-61061
01/20/2025, 9:18 AMlistIdentities
method indeed has a credentials_identifier
parameter. However, it seems that this parameter might not be directly exposed in the Go SDK as CredentialsIdentifier
. Instead, the Go SDK appears to offer the following parameters for the ListIdentities
method: 1. PerPage
(per_page in the API) 2. Page
(page in the API) 3. PageSize
(page_size in the API) 4. PageToken
(page_token in the API) To use the credentials_identifier
parameter with the Go SDK, you might need to use a more generic method to set query parameters. However, the current SDK documentation doesn't clearly show how to do this. As an alternative approach, you could retrieve all identities and filter them on the client side, but this is not efficient for large datasets. Here's what you can do: 1. Check if there's a newer version of the SDK that includes the CredentialsIdentifier
parameter. 2. If not, you might need to use the REST API directly instead of the SDK for this specific operation. 3. You can also open an issue on the [ory/kratos-client-go GitHub repository](https://github.com/ory/kratos-client-go) to request this feature be added to the SDK. I apologize again for the confusion. If you need to perform this operation urgently, you might want to consider using the REST API directly or implementing a client-side filtering solution as a temporary workaround.