title: Identity Server 4 - Getting invalid_client error
body: <p>I am new to Identity Server. I haven't configured it before. But I need it for a Project I am working on.</p>
  
  <p>The API will be serving an Angular JS Client, iOS App and an Android App. We need to implement authentication and authorisation.</p>
  
  <p><strong>Note:</strong> I am trying to configure Identity Server and my API in the same Web API project.</p>
  
  <p>I have followed the documentation and configured Identity Server as the following:</p>
  
  <p>In startup.cs, in <code>ConfigureServices()</code></p>
  
  <pre><code>        services.AddTransient&lt;IProfileService, CustomProfileService&gt;();
          services.AddTransient&lt;IResourceOwnerPasswordValidator, CustomResourceOwnerPasswordValidator&gt;();
  
  
  
          services.AddIdentityServer()
              .AddTemporarySigningCredential()
              // add the resources that need to be secured
              .AddInMemoryApiResources(IdentityServerConfig.Resources.GetApiResources())
              // add the clients that will be access the ApiResources
              .AddInMemoryClients(IdentityServerConfig.Clients.GetClients());
  </code></pre>
  
  <p>The <code>CustomProfileService</code> and <code>CustomResourceOwnerPasswordValidator</code> and the same as this answer:  <a href="https://stackoverflow.com/a/35306021/1910735">https://stackoverflow.com/a/35306021/1910735</a></p>
  
  <p>In <code>Configure()</code></p>
  
  <pre><code>        // as this API will also be acting as an
          app.UseIdentityServer();
  
  
          // now setup the Identity Server client, this API will also be the client 
  
          app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
          {
              Authority = "http://localhost:44337",
              RequireHttpsMetadata = false,
  
  
              ApiName = "obApi"
          });
  </code></pre>
  
  <p>Here is the <code>GetClients()</code></p>
  
  <pre><code>    public static IEnumerable&lt;Client&gt; GetClients()
      {
          var clients = new List&lt;Client&gt;();
  
  
  
          var websiteGrants = new List&lt;string&gt; { GrantType.ResourceOwnerPassword };
          var secret = new Secret("secret".Sha256());
  
          var websiteClient = new Client()
          {
              // we will be using Angular JS to access the API - so naming it js
              ClientId = "js",
  
              // just a human friendly name
              ClientName = "JavaScript Client",
  
              // set to GrantType.ResourceOwnerPassword - because using Username/Password to login
              AllowedGrantTypes = websiteGrants, 
  
              // secret for authentication
              //TODO: Change the secret 
              ClientSecrets = { secret },
  
              // we need to access the fhApi from Angular JS front-end 
              // fhApi is defined in Resources file as an API Resource
              AllowedScopes = { "obApi" }
          };
  
  
          clients.Add(websiteClient);
  
          return clients;
      }
  </code></pre>
  
  <p>and here is the <code>GetApiResources()</code></p>
  
  <pre><code>    public static IEnumerable&lt;ApiResource&gt; GetApiResources()
      {
          // e.g. if we want to protect an API called api1 - then we will add it here
          // these values are hard coded for now - but we can get from DB, config file etc.
  
          return new List&lt;ApiResource&gt;
                          {
                              new ApiResource("obApi", "Order2Bite API")
                          };
      }
  </code></pre>
  
  <p>Now because I want to use it Angular JS, iOS and Android I want to just get the Access Token from the Identity Server, and then use the Access Token for Authentication and Authorisation.</p>
  
  <p>for this I am trying to access the <code>/connect/token</code> from a JS client</p>
  
  <p>But I am getting an <code>invalid_client</code> error.</p>
  
  <pre><code>        var user = { client_id: "js", grant_type: 'password', username: "testuser", password: "testpasswrd", scope: 'obApi' };
  
          var urlEncodedUrl = {
              'Content-Type': 'application/x-www-form-urlencoded',
          };
  
          this.$http({
              method: 'POST', url: "http://localhost:44337/connect/token",
              headers: urlEncodedUrl,
              data: user,
  
          })
              .then(data =&gt; {
                  console.log(data)
              },
              data =&gt; {
                  console.log(data)
  
              });
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/HDfuh.png" rel="noreferrer"><img src="https://i.stack.imgur.com/HDfuh.png" alt="enter image description here"></a></p>
  
  <p>The error I get on the server side is ' No client identifier found':
  <a href="https://i.stack.imgur.com/44Skt.png" rel="noreferrer"><img src="https://i.stack.imgur.com/44Skt.png" alt="enter image description here"></a></p>
  
  <p>1 - Why am I getting this error?</p>
  
  <p>2 - As I need to get the Token programmatically in JS, Android and iOS, I need to use <code>/connect/token</code>, am I correct on this? Am I on the correct path?</p>