Welcome to the Kinde community

Updated 7 months ago

Getting a user's email from a dotnet backend api

At a glance
The post asks how to get a user's email from a .NET backend API. The comments provide two solutions:

1. Use the `GetUser` or `GetUserProfileV2` methods from the `OAuthApi` class in the Kinde SDK. This involves setting up the configuration, creating instances of `HttpClient` and `OAuthApi`, and calling the `GetUser` method to retrieve the user's profile, including their email address.

2. Use the `/oauth2/v2/user_profile` endpoint, which is the userinfo endpoint in Kinde. You can make a GET request to this endpoint to retrieve the details of the currently logged-in user, including their email address.

There is no explicitly marked answer, but the community members have provided two potential solutions.

how can I get a users email from a dotnet backend api

K
R
3 comments

To get a user's email from a .NET backend API using the Kinde SDK, you can use the `GetUser` or `GetUserProfileV2` methods from the `OAuthApi` class. Below is an example of how to do this: 1. *Set up your configuration:* Ensure you have your configuration set up with the base path and access token. 2. *Create instances of `HttpClient` and `OAuthApi`:* These instances will be used to make the API call. 3. *Call the `GetUser` or `GetUserProfileV2` method:* This method will return the user's profile, including their email. Here is a sample code snippet: ``` using System.Collections.Generic; using System.Diagnostics; using System.Net.Http; using Kinde.Api.Api; using Kinde.Api.Client; using Kinde.Api.Model; namespace Example { public class GetUserExample { public static void Main() { Configuration config = new Configuration(); config.BasePath = ""; // Configure Bearer token for authorization: kindeBearerAuth config.AccessToken = "YOUR_BEARER_TOKEN"; // create instances of HttpClient, HttpClientHandler to be reused later with different Api classes HttpClient httpClient = new HttpClient(); HttpClientHandler httpClientHandler = new HttpClientHandler(); var apiInstance = new OAuthApi(httpClient, config, httpClientHandler); try { // Get User Profile UserProfile result = apiInstance.GetUser(); Debug.WriteLine(result.Email); } catch (ApiException e) { Debug.Print("Exception when calling OAuthApi.GetUser: " + e.Message); Debug.Print("Status Code: " + e.ErrorCode); Debug.Print(e.StackTrace); } } } } ``` In this example, replace `"YOUR_BEARER_TOKEN"` with your actual bearer token. The `GetUser` method will return a `UserProfile` object, from which you can access the `Email` property.

what is the userinfo endpoint URL in kinde

The userinfo endpoint URL in Kinde is `/oauth2/v2/user_profile`. You can make a GET request to this endpoint to retrieve the details of the currently logged-in user, including their email address. For example, the full URL would be: ``` https://{businessName}. ``` Replace `{businessName}` with your actual business name.

Add a reply
Sign up and join the conversation on Slack