title: Operation returned an invalid status code 'Unauthorized''
body: <p>I am trying to embed a sample Power BI dashboard in a WPF application following the sample project and sort of tutorial from <a href="https://blogs.msdn.microsoft.com/premier_developer/2018/01/27/integrate-power-bi-dashboards-reports-and-tiles-into-a-wpf-application/" rel="nofollow noreferrer">here</a>. When I launch the app, I have to enter my password to authenticate myself and when it tries to get the list of my Power BI workspaces with the <code>getAppWorkspacesList()</code> I am getting this error message </p>
  
  <blockquote>
    <p>Microsoft.Rest.HttpOperationException: 'Operation returned an invalid
    status code 'Unauthorized''</p>
  </blockquote>
  
  <p>Can someone please help in pointing out why this error is occuring? I tried to look into the details of the error, but I am not understanding what could be causing the issue. I was able to embed a dashboard in a .Net Web App without an issue, so I don't think the problem is in my Power BI or Azure Directory account. </p>
  
  <p><a href="https://i.stack.imgur.com/2hbAa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2hbAa.png" alt="enter image description here"></a></p>
  
  <pre><code>private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
  private static string tenant = ConfigurationManager.AppSettings["ida:Tenant"];
  private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
  Uri redirectUri = new Uri(ConfigurationManager.AppSettings["ida:RedirectUri"]);
  private static string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
  
  private static string graphResourceId = ConfigurationManager.AppSettings["ida:ResourceId"];
  private AuthenticationContext authContext = null;
  
  TokenCredentials tokenCredentials = null;
  string Token = null;
  string ApiUrl = "https://api.powerbi.com";
  
  
  
  public MainWindow()
  {
      InitializeComponent();
      TokenCache TC = new TokenCache();
      authContext = new AuthenticationContext(authority, TC);
  }
  
  
  private void getAppWorkspacesList()
  {
      using (var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials))
      {
          appWorkSpacesList.ItemsSource = client.Groups.GetGroups().Value.Select(g =&gt; new workSpaceList(g.Name, g.Id));                
      }
  }
  </code></pre>