После развертывания ASP. NET веб-API для получения «ошибка»: «unsupported_grant_type» - PullRequest
0 голосов
/ 24 апреля 2020

проверено ASP. NET Веб-API в локальной среде все работает нормально, но после развертывания на хост-сервере я получаю "unsupported_grant_type" Вот мой код

EnableCorsAttribute cors = new EnableCorsAttribute("*", "*", "*");
        config.EnableCors(cors);
        // Web API routes
        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

Контроллер

public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }

    //This resource is For all types of role
    [Authorize(Roles = "SuperAdmin, Admin, User")]
    [HttpGet]
    [Route("api/login")]
    public IHttpActionResult GetValues()
    {
        var identity = (ClaimsIdentity)User.Identity;
        var roles = identity.Claims
                    .Where(c => c.Type == ClaimTypes.Role).Select(c => c.Value);
        var LogTime = identity.Claims
                  .FirstOrDefault(c => c.Type == "LoggedOn").Value;
        return Ok("Hello: " + identity.Name + ", " +
            "Your Role(s) are: " + string.Join(",", roles.ToList()) +
            "Your Login time is :" + LogTime);
    }

класс запуска

public void Configuration(IAppBuilder app)
    {
        ConfigureAuth(app);

        //GlobalConfiguration.Configure(WebApiConfig.Register);
        //FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        //RouteConfig.RegisterRoutes(RouteTable.Routes);
        //BundleConfig.RegisterBundles(BundleTable.Bundles);
    }

    public void ConfigureAuth(IAppBuilder app)
    {
        //this is very important line cross orgin source(CORS)it is used to enable cross-site HTTP requests
        //For security reasons, browsers restrict cross-origin HTTP requests
        app.UseCors(CorsOptions.AllowAll);

        var OAuthOptions = new OAuthAuthorizationServerOptions
        {
            AllowInsecureHttp = true,
            TokenEndpointPath = new PathString("/token"),
            AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30),//token expiration time
            Provider = new OauthProvider()
        };

        app.UseOAuthBearerTokens(OAuthOptions);
        app.UseOAuthAuthorizationServer(OAuthOptions);
        app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());

        HttpConfiguration config = new HttpConfiguration();
        WebApiConfig.Register(config);//register the request
    }

Global

void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        GlobalConfiguration.Configure(WebApiConfig.Register);

    }

Test on local

Test on host

Те же параметры, что и в Postman, работают нормально, но я получаю эту ошибку на хост-сервере. Пожалуйста, помогите

...