title: Getting 401 Unauthorized with valid access token using identity server 4 with Asp.net Core API
body: <p>I am using Identity server 4 in my Asp.net core API Application , i am getting successful token on <strong>local</strong> server 
  <a href="https://localhost:[port]/connect/token" rel="noreferrer">https://localhost:[port]/connect/token</a> 
  and it gives access token and when i use the bearer token to access authorize method then it <strong>working fine</strong> <br/>but <strong>on server</strong>
  <a href="https://example.com/connect/token" rel="noreferrer">https://example.com/connect/token</a> it also give successful token but when i use this token to access authorize method then it give <strong>401 unauthorized error</strong></p>
  
  <pre><code>  "Authority": "https://example.com",
    "Audience": "https://example.com/resources",
    "RequireHttpsMetadata": "true"
  
  
   services.AddIdentityServer(options =&gt;
          {
              options.Events.RaiseErrorEvents = true;
              options.Events.RaiseInformationEvents = true;
              options.Events.RaiseFailureEvents = true;
              options.Events.RaiseSuccessEvents = true;
          })
              .AddDeveloperSigningCredential()
              .AddInMemoryPersistedGrants()
              .AddInMemoryIdentityResources(GetIdentityResources())
              .AddInMemoryApiResources(GetApiResources())
              .AddInMemoryClients(GetClients())
              .AddAspNetIdentity&lt;User&gt;();
  
          services.AddAuthentication(options =&gt;
          {
              options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
              options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
          })
          .AddJwtBearer(options =&gt;
            {
                options.Authority = configuration["AppSettings:Authority"];
                options.Audience = configuration["AppSettings:Audience"];
                options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AppSettings:RequireHttpsMetadata"]);
            });
          services.AddTransient&lt;IProfileService, IdentityClaimsProfileService&gt;();
  
  
  
      public static IEnumerable&lt;IdentityResource&gt; GetIdentityResources()
      {
          return new List&lt;IdentityResource&gt;
          {
              new IdentityResources.OpenId(),
              new IdentityResources.Email(),
              new IdentityResources.Profile(),
          };
      }
      public static IEnumerable&lt;ApiResource&gt; GetApiResources()
      {
          return new List&lt;ApiResource&gt;
          {
              new ApiResource("api1", "My API")
          };
      }
      public static IEnumerable&lt;Client&gt; GetClients()
      {
          // client credentials client
          return new List&lt;Client&gt;
          {
  
              // resource owner password grant client
              new Client
              {
                  ClientId = "ro.angular",
                  AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
  
                  ClientSecrets =
                  {
                      new Secret("secret".Sha256())
                  },
                  AllowedScopes = {
                      IdentityServerConstants.StandardScopes.OpenId,
                      IdentityServerConstants.StandardScopes.Profile,
                      IdentityServerConstants.StandardScopes.Email,
                      IdentityServerConstants.StandardScopes.Address,
                      "api1"
                  },
                  AllowOfflineAccess = true,
                  RefreshTokenUsage = TokenUsage.ReUse,
                  RefreshTokenExpiration = TokenExpiration.Sliding
  
              }
          };
      }
  </code></pre>