内部部署WebApi不会重定向到身份验证

时间:2015-06-30 10:37:49

标签: c# asp.net asp.net-web-api adfs

由于某些原因,OWIN没有重定向到ADFS中指定的登录页面, 我没有对ADFS(Windows Server 2012)的任何控制,我遵循Microsoft文档(http://www.asp.net/visual-studio/overview/2013/creating-web-projects-in-visual-studio#orgauthonprem),但我现在卡住了。 我认为通过引用元数据,所有内容都可以直接配置。

我的控制器(从WebApi生成的模板)

[Authorize]
public class ValuesController : ApiController
{
    // GET api/values
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }

    // GET api/values/5
    public string Get(int id)
    {
        return "value";
    }

    // POST api/values
    public void Post([FromBody]string value)
    {
    }

    // PUT api/values/5
    public void Put(int id, [FromBody]string value)
    {
    }

    // DELETE api/values/5
    public void Delete(int id)
    {
    }
}

但是我得到了

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Message>Authorization has been denied for this request.</Message>
</Error>

我应该实施某种基础身份验证吗?

更新<!/强>
似乎有必要使用Microsoft.Owin.Security.WsFederation
但是现在adfs并没有重定向到我的领域,我在用户通过身份验证后从ADFS获得了302.像

这样的东西
/adfs/ls/?wtrealm=http%3a%2f%2flocalhost%3a554&wctx=WsFedOwinState%3d9C7kwsHRjBM86yrii5niUWF1gW9VFvCKBTj_D3z4-QQ5P25opteVK0mWf0fudEQdsgIexkHxTxhKDqBmfSWNAuJ3togHTBE40CEKYa8JLKJOxsgxNGIreYBOzNYzK8NNvR26PCMCowCFoM9NGJOC8w&wa=wsignin1.0

我的Startup.cs

public partial class Startup
{
    // For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
    public void ConfigureAuth(IAppBuilder app)
    {
        app.SetDefaultSignInAsAuthenticationType(WsFederationAuthenticationDefaults.AuthenticationType);

        app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions
        {
            MetadataAddress = ConfigurationManager.AppSettings["ida:AdfsMetadataEndpoint"],
            Wtrealm = ConfigurationManager.AppSettings["ida:Audience"],
        });
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = WsFederationAuthenticationDefaults.AuthenticationType
        });
    }
}

如何告诉ADFS重定向到领域?

1 个答案:

答案 0 :(得分:1)

我发现ADFS需要一个具有唯一ID的依赖方来验证用户并正确地重定向到领域。