首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ASP.NET MVC 4.5.2连接到IdentityServer4

ASP.NET MVC 4.5.2连接到IdentityServer4
EN

Stack Overflow用户
提问于 2016-09-22 15:08:48
回答 1查看 5.1K关注 0票数 11

我有一个运行在ASP.NET MVC 4.5.2上的网站。我有一个IdentityServer4服务器正在运行,但是当我尝试对它进行身份验证时,我得到了一个:

代码语言:javascript
复制
invalid_request

对于ASP.NET Core,文档有:

代码语言:javascript
复制
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationScheme = "Cookies"
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
    AuthenticationScheme = "oidc",
    SignInScheme = "Cookies",

    Authority = "http://localhost:5000",
    RequireHttpsMetadata = false,

    ClientId = "mvc",
    SaveTokens = true
});

我在我的项目NuGet中包含了下面的Microsoft.Owin.Security.OpenIdConnect包。我的代码如下:

代码语言:javascript
复制
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = "Cookies"
        });
        app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
        {
            AuthenticationType = "oidc",
            SignInAsAuthenticationType = "Cookies",

            Authority = "http://localhost:5000",

            ClientId = "mvc",
        });

如何正确地连接到它呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-29 13:15:10

好的,我开始工作了。

您需要向解决方案Microsoft.Owin.Security.OpenIdConnect中添加以下NuGet包。

我的Startup.Auth.cs包含

代码语言:javascript
复制
 public void ConfigureAuth(IAppBuilder app)
        {

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = "Cookies"
            });

            app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
            {
                Authority = "http://localhost:5000", //ID Server
                ClientId = "demo",
                ResponseType = "id_token code",
                SignInAsAuthenticationType = "Cookies",
                RedirectUri = "http://localhost:51048/signin-oidc", //URL of website
                Scope = "openid",               
            });

        }

我在IdentityServer中的客户端配置是:

代码语言:javascript
复制
 public static IEnumerable<Client> GetClients()
        {
            return new List<Client> {
                new Client {
                    ClientId = "demo",
                    AllowedScopes = new List<string> { "openid"},
                    AllowedGrantTypes = GrantTypes.Hybrid,
                    RedirectUris = new List<string>{"http://localhost:51048/signin-oidc"},

                }
            };
        }
票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39642715

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档