繁体   English   中英

在ASP.NET MVC API中使用oAuth

[英]Using oAuth in a ASP.NET MVC API

我最近遵循了有关令牌认证的教程,并且我希望将令牌端点设置为/api/v1/login 为了使它不干扰我构建的api,我添加了config.Routes.IgnoreRoute("Login Route v1", "api/v1/login"); 到我的WebApiConfig.cs。 为了使oAuth令牌正确,我将Startup.cs更改为

using Microsoft.Owin;
using Microsoft.Owin.Security.OAuth;
using Owin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;

[assembly: OwinStartup(typeof(Project.Startup))]
namespace Project
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureOAuth(app);
            //Rest of code is here;
        }

        public void ConfigureOAuth(IAppBuilder app)
        {
            OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
            {
                AllowInsecureHttp = true,
                TokenEndpointPath = new PathString("/api/v1/login"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
                Provider = new SimpleAuthorizationServerProvider()
            };

            // Token Generation
            app.UseOAuthAuthorizationServer(OAuthServerOptions);
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());

        }
    }
}

不幸的是,端点仍然位于/token ,我该如何更改?

这种方法是绝对正确的,但是不幸的是,该代码再次在项目中使用/token PathString,因此它覆盖了此配置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM