Wenn Sie dieses Problem gestoßen sind, sollten Sie überprüfen, ob die Startup.Auth die app.UseOAuthBearerTokens hat, manchmal Sie die OAuthAuthorizationServerOptions erstellen, aber nicht gelten sie:
Startup.Auth.cs
// Configure the application for OAuth based flow
PublicClientId = "self";
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/Token"),
Provider = new OAuthServerProvider(PublicClientId),
AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(365),
// In production mode set AllowInsecureHttp = false
AllowInsecureHttp = true
};
// Enable the application to use bearer tokens to authenticate users
app.UseOAuthBearerTokens(OAuthOptions);
Dann schauen sie sich Ihre Web-Api Routen Konfigurationsklasse, stellen sie sicher, dass es die SuppressDefaultHostAuthentication ruft:
WebApiConfig.cs
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultController",
routeTemplate: "api/{controller}/{action}",
defaults: new { id = RouteParameter.Optional }
);
// Register Additional Filters
config.Filters.Add(new WebApiPlatformFilters());
}