Auth0 Home Blog Docs

Getting ApiException: Unauthorized .Net AuthenticationApiClient

aspnet-core

#1

Hi

I’m trying to get /userinfo using the .Net SDK AuthenticationApiClient, but I can only get the I allways end up with the ApiException: Unauthorized.

In the Startup I have the options.Scope.Add("openid"); in my scopes.

My code itself:

  public object UserInformation {  get
  	{
  		if(_userInformation == null)
  		{
  			string accessToken = _User.Claims.FirstOrDefault(c => c.Type == "access_token").Value;

  			if (!string.IsNullOrEmpty(accessToken))
  			{
  				var apiClient = new AuthenticationApiClient(new Uri("https://xxx.eu.auth0.com"));
  				var userInfo = apiClient.GetUserInfoAsync(accessToken).Result;
  				this._userInformation = userInfo;
  			}
  		}

  		return this._userInformation;
  	}
  }

I’ve spent many hours now scouring the docs and other resources, and could really use a pointer right now :smiley: