-1
我正在嘗試使用IdentityServer3,因此我將通過官方示例。我已經創建了一個授權服務器,這是非常簡單的:如何爲IdentityServer3設置MVC客戶端
namespace SimpleIdentityServer
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
var options = new IdentityServerOptions
{
Factory = new IdentityServerServiceFactory()
.UseInMemoryClients(Clients.Get())
.UseInMemoryScopes(Scopes.Get())
.UseInMemoryUsers(Users.Get()),
RequireSsl = false
};
app.UseIdentityServer(options);
}
}
}
這是我記憶用戶:
new Client
{
ClientName = "MVC application",
ClientId = "mvc",
Enabled = true,
AccessTokenType = AccessTokenType.Jwt,
Flow = Flows.Implicit,
ClientSecrets = new List<Secret>
{
new Secret("secret".Sha256())
},
AllowedScopes = new List<string>
{
"openId",
"profile"
},
RedirectUris = new List<string>
{
"http://localhost:12261/"
}
}
現在,我想使用上述服務器的MVC應用程序的用戶進行身份驗證,所以我這樣做:
public void Configuration(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies"
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
Authority = "http://localhost:47945/",
ClientId = "mvc",
RedirectUri = "http://localhost:12261/",
ResponseType = "id_token",
SignInAsAuthenticationType = "Cookies"
});
}
這是與Authorize
屬性標註的樣本控制器動作:
[Authorize]
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}
但是,當我回家/關於我的mvc應用程序時,它顯示我401錯誤,它似乎(從serilog)它甚至不會調用授權服務器。
您是否從Identity Server獲取任何錯誤?假設您的身份服務器作爲默認運行並且綁定到/ core /,您的客戶端中的Authority應該是http:// localhost:47945/core /。另外,您可能需要告訴客戶端網站允許使用外部Cookie: app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); –
@NickBork實際上,我已經在自託管的控制檯應用程序上實現了Identity Server:WebApp.Start(「http:// localhost:47945」)'。無論如何,我沒有得到任何錯誤。而且,我還沒有添加任何映射(在服務器的啓動配置方法中)。 –
mok
@NickBork'app.UseExternalSignInCookie(DefaultAuthenticationTypes.Exter nalCookie); '沒有改變任何東西。 – mok