# Sample code for GetUserInfoAsync() by C#

**URL:** <https://community.auth0.com/t/sample-code-for-getuserinfoasync-by-c/85225>\
**Category:** Get Help\
**Tags:** auth0\
**Created:** [June 16, 2022, 8:25am UTC](https://community.auth0.com/t/sample-code-for-getuserinfoasync-by-c/85225 "2022-06-16T08:25:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![yfujita](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yfujita/32/37753_2.png) [@yfujita](https://community.auth0.com/u/yfujita)\
**Post date:** [June 16, 2022, 8:25am UTC](https://community.auth0.com/t/sample-code-for-getuserinfoasync-by-c/85225/1 "2022-06-16T08:25:29Z")

</div>

Hello.  
Where can I find sample code for GetUserInfoAsync() in C#?  
I have been trying to get user info but have not been successful.  
I’m assuming there is something wrong with getting the token,  
but there may be something else wrong,  
so if you have a sample where I can see the whole procedure from the beginning,  
please let me know.

---

<div class="post-metadata">

**Author:** ![b.abakzahedi7141](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/b.abakzahedi7141/32/34072_2.png) [@b.abakzahedi7141](https://community.auth0.com/u/b.abakzahedi7141)\
**Post date:** [June 17, 2022, 9:35am UTC](https://community.auth0.com/t/sample-code-for-getuserinfoasync-by-c/85225/2 "2022-06-17T09:35:15Z")

</div>

Thank you for thinking of me[.](https://www.myallsaversconnect.org/)

---

<div class="post-metadata">

**Author:** ![yfujita](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yfujita/32/37753_2.png) [@yfujita](https://community.auth0.com/u/yfujita)\
**Post date:** [June 20, 2022, 6:22am UTC](https://community.auth0.com/t/sample-code-for-getuserinfoasync-by-c/85225/3 "2022-06-20T06:22:13Z")

</div>

> **[Auth0 UWP SDK Quickstarts: Login](https://auth0.com/docs/quickstart/native/windows-uwp-csharp/01-login)**
>
> This tutorial demonstrates how to add user login to a UWP C# application using Auth0.

In the MainPage#DisplayResult method of the above sample code

var userInfo = await client.GetUserInfoAsync(loginResult.AccessToken);

and added GetUserInfoAsync works.

However, the information I got was the same as what the loginResult contains.  
I would like to get the other user’s information, like the Auth0 dashboard can display it.

---

<div class="post-metadata">

**Author:** ![yfujita](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yfujita/32/37753_2.png) [@yfujita](https://community.auth0.com/u/yfujita)\
**Post date:** [June 21, 2022, 2:13am UTC](https://community.auth0.com/t/sample-code-for-getuserinfoasync-by-c/85225/4 "2022-06-21T02:13:24Z")

</div>

[https://auth0.github.io/auth0.net/](https://auth0.github.io/auth0.net/)

I am trying the ManagementApiClient class step by step, looking at the above. I used loginResult.AccessToken for token, and the connection seems to succeed.  
However, I get a CS7036 error at the following location.

var allClients = await apiClient.Clients.GetAllAsync();

---

<div class="post-metadata">

**Author:** ![yfujita](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yfujita/32/37753_2.png) [@yfujita](https://community.auth0.com/u/yfujita)\
**Post date:** [June 23, 2022, 7:26am UTC](https://community.auth0.com/t/sample-code-for-getuserinfoasync-by-c/85225/5 "2022-06-23T07:26:04Z")

</div>

[Getting a users information from Auth0](https://serversncode.com/getting-users-information-from-auth0/#:~:text=To%20get%20the%20user%20information%20from%20the%20Auth0,pretty%20much%20it.%20Those%202%20lines%20of%20code).

I found the above site and did the following.  
The IntelliSense response was promising.  
Unfortunately, it throws an exception.

> apiClient = new ManagementApiClient(loginResult.AccessToken, new Uri(“https://_**.auth0.com/api/v2/"));  
> var memberId = "**_”;  
> var memberInfo = await apiClient.Users.GetAsync(memberId);

* * *

Auth0.Core.Exceptions.ErrorApiException  
HResult=0x80131500  
Message=Bad HTTP authentication header format  
Source=Auth0.ManagementApi  
stack trace:  
at Auth0.ManagementApi.HttpClientManagementConnection.d\_\_19`1.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Auth0.ManagementApi.HttpClientManagementConnection.<GetAsyncInternal>d__15`1.MoveNext()  
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()  
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)  
at Auth0.ManagementApi.HttpClientManagementConnection.\<\>c\_\_DisplayClass13\_0`1.<<GetAsync>b__0>d.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Auth0.ManagementApi.HttpClientManagementConnection.<Retry>d__26`1.MoveNext()  
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()  
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)  
at Auth0.ManagementApi.HttpClientManagementConnection.d\_\_13`1.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()  
at UWPSample.MainPage.d\_\_5.MoveNext()

---

<div class="post-metadata">

**Author:** ![yfujita](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yfujita/32/37753_2.png) [@yfujita](https://community.auth0.com/u/yfujita)\
**Post date:** [June 24, 2022, 9:48am UTC](https://community.auth0.com/t/sample-code-for-getuserinfoasync-by-c/85225/6 "2022-06-24T09:48:59Z")

</div>

Yes!!!  
Finally I have successfully retrieved the user data with the code below.  
Next I want to retrieve the list of users. Please tell me about the ??? below.  
var allUser = await apiClient.Users.GetAllAsync(???) ;

> /\*  
> \*\* Get Management API Access Tokens for Production  
> \*\* [Get Management API Access Tokens for Production](https://auth0.com/docs/secure/tokens/access-tokens/get-management-api-access-tokens-for-production)  
> \*/  
> var restClient = new RestClient(“[https://xxxxxxxxxxxxxxxxx.auth0.com/oauth/token](https://xxxxxxxxxxxxxxxxx.auth0.com/oauth/token)”);  
> var request = new RestRequest(“”, Method.Post);  
> request.AddHeader(“content-type”, “application/x-www-form-urlencoded”);  
> var clientId = “xxxxxxxxxxxxxxxxxx”;//Machine to Machine  
> var clientSecret = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”; //Machine to Machine  
> var audience = “[https://xxxxxxxxxxxx.auth0.com/api/v2/](https://xxxxxxxxxxxx.auth0.com/api/v2/)”;  
> request.AddParameter(  
> “application/x-www-form-urlencoded”,  
> $“grant\_type=client\_credentials&client\_id={clientId}&client\_secret={clientSecret}&audience={audience}”,  
> ParameterType.RequestBody  
> );  
> RestResponse response = restClient.Execute(request);  
> var obj = JsonConvert.DeserializeObject(response.Content);  
> string token = obj.access\_token;
> 
> /\*  
> \*\* Get User Info  
> \*\* [Getting a users information from Auth0](https://serversncode.com/getting-users-information-from-auth0/#:~:text=To%20get%20the%20user%20information%20from%20the%20Auth0,pretty%20much%20it.%20Those%202%20lines%20of%20code).  
> \*/  
> var apiClient = new ManagementApiClient(token, new Uri(“[https://xxxxxxxxxxx.auth0.com/api/v2/](https://xxxxxxxxxxx.auth0.com/api/v2/)”));  
> var userId = “xxxxxxxxxxxxxxxxxxxxxxxxx”;  
> var userInfo = await apiClient.Users.GetAsync(userId);  
> Console.WriteLine($“fullname: {userInfo.FullName}”);  
> Console.WriteLine($“Email: {userInfo.Email}”);

---

<div class="post-metadata">

**Author:** ![yfujita](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/yfujita/32/37753_2.png) [@yfujita](https://community.auth0.com/u/yfujita)\
**Post date:** [June 27, 2022, 5:36am UTC](https://community.auth0.com/t/sample-code-for-getuserinfoasync-by-c/85225/7 "2022-06-27T05:36:08Z")

</div>

It is done for now.

> var users = apiClient.Users.GetAllAsync(new GetUsersRequest());

I don’t understand how to use GetUsersRequest from the manual,  
so can you give me some specific examples?

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 22, 2022, 10:49am UTC](https://community.auth0.com/t/sample-code-for-getuserinfoasync-by-c/85225/8 "2022-12-22T10:49:26Z")

</div>


