我遇到一个问题,我似乎无法让我的身份服务器注销以首先显示确认。我从github下载了IdentityServer4的源代码,在Models文件夹中找到了参数:LogoutRequest.cs、ShowSignOutPrompt。除了在注销期间检查之外,IdentityServer 中没有对其进行任何引用。
在调试中,我发现它是错误的。我不知道应该在哪里设置,我已经检查了服务器和客户端上的客户端配置选项,以及服务器启动的选项。
我在客户端代码中找不到“ShowSignoutPrompt”的实例(我当前使用的是 IdentityServer3 Owin 混合客户端示例)。
代码流程如下:我们的默认布局中有一个按钮,可以触发客户端的 AccountController.Signout():
public void Signout()
{
Request.GetOwinContext().Authentication.SignOut();
}
Run Code Online (Sandbox Code Playgroud)
从那里开始,我不太确定如何实现,但下一个点是 IdentityServer 的 AccountController.Logout(string logoutId)。该方法构建注销提示视图(使用 AccountServices.BuildLogoutViewModelAsync 中的检查)并将其返回到用户的浏览器。不将 ShowSignoutPrompt 设置为 false 的唯一正常工作方法是将 PostLogoutRedirectUri 设置为“/signout-callback-oidc”。我不知道为什么。
当用户在上面生成的视图上单击“yes”时,它将转到 IdSrvr 的 AccountController.Logout(LogoutInputModel model)。我正在尝试更改该方法的最后一行:
return View("LoggedOut", vm);
Run Code Online (Sandbox Code Playgroud)
到:
return Redirect(vm.PostLogoutRedirectUri);
Run Code Online (Sandbox Code Playgroud)
这里还有另一个问题,即使我在客户端配置上设置了 PostRedirectUri,这里的 PostRedirectUri 也是空的(好吧,就此而言,Identity Server 的客户端配置也有它)。
我对如何使用它感到困惑。
我见过的大多数示例都将其指定为“ / signout-callback-oidc”。这似乎表明它在此过程中使用了OIDC中间件。如果我想返回特定的客户页面怎么办?
当我将IdentityServer的AutomaticRedirectAfterSignOut的AccountOptions.cs属性设置为true时,自动重定向不起作用。此外,在注销期间,我没有收到客户端的PostLogoutRedirectUri。
那么,该链接应该转到OIDC中间件,还是可以用于重定向到客户端?
到目前为止,我已经看到了如何为客户端 webapp 的 cookie 设置过期时间(谢谢 v0id):IdentityServer4 cookie expires
IdentityServer4 实际上使用了两个 cookie——客户端 cookie 和服务器 cookie(“idsrv”)。
如果我按照此处给出的方式设置客户端 cookie 过期时间: IdentityServer4 cookie 过期时间, 那么当我关闭浏览器并返回到需要授权的客户端 webapp 页面时,我的访问被拒绝,因为浏览器会话不再具有服务器 cookie。
所以我需要一种方法来将“idsrv”cookie 过期时间设置为与客户端相同。
目前,我看到的设置服务器 cookie(它被忽略或以某种方式删除)的最佳方法是 IdentityServer4 主机 Startup.cs / ConfigureServices() 方法中的以下代码块:
services.AddIdentityServer(options =>
{
options.Authentication.CookieLifetime = new TimeSpan(365, 0, 0, 0);
options.Authentication.CookieSlidingExpiration = true;
})
Run Code Online (Sandbox Code Playgroud)
这应该将 cookie 的到期时间设置为一年后。但是,在应用程序选项卡下的 Chrome 开发人员工具 cookie 中,我看到它仍然具有 1969 年的过期过期默认日期。
我下载了 IdentityServer4 项目源,删除了 nuget 包,并将源项目添加到我的解决方案中,以便我可以通过它进行调试。
我看到它得到了我在 ConfigureInternalCookieOptions.cs / Configure() 方法中给它的到期时间。它也匹配内部的 DefaultCookieAuthenticationScheme/应用属性。我没有发现任何特定于 IdentityServer 的东西会忽略我设置的到期日期,但它仍然有 1969 年的到期日期。
编辑:我尝试将 cookie 持久设置在 IdentityServer 主机的 AccountController 中,如下所示(有趣的是,Microsoft …
我已经成功构建了 Docker 镜像并在 Docker swarm 中运行它们。当我尝试构建映像并使用 Docker Desktop 的 Kubernetes 集群运行它时:
docker build -t myimage -f myDockerFile .
Run Code Online (Sandbox Code Playgroud)
(以上成功在docker本地注册表中创建了一个镜像)
kubectl run myapp --image=myimage:latest
Run Code Online (Sandbox Code Playgroud)
(据我了解,这和使用 kubectl create 部署命令是一样的)
上面的命令成功创建了一个部署,但是当它创建一个pod时,pod状态总是显示:
NAME READY STATUS RESTARTS AGE
myapp-<a random alphanumeric string> 0/1 ImagePullBackoff 0 <age>
Run Code Online (Sandbox Code Playgroud)
我不确定为什么它在拉取图像时遇到问题 - 它可能不知道 docker 本地图像在哪里?
我在 IdentityServer4 主机端配置了以下客户端:
new Client
{
ClientId = "myClient",
....
RedirectUris = {"https://localhost:44001/home/claims",
"https://localhost:44001/"}
....
}
Run Code Online (Sandbox Code Playgroud)
我目前正试图让它以这样一种方式返回,无论它来自客户端应用程序中的哪个控制器,它都能正常工作(因为在客户端应用程序启动时配置了 redirectURI 并且必须匹配服务器的客户端配置)。
在客户端应用启动时,相关代码:
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
...
ClientId = "myClient",
RedirectUri = "https://localhost:44001/",
...
}
Run Code Online (Sandbox Code Playgroud)
当我在客户端启动时将 redirectUri 设置为上面的第二个选项“ https://localhost:44001 ”时,我被重定向到客户端错误控制器,并出现以下错误:
“抱歉,出现错误:unknown_client Invalid redirect_uri”。
此外,服务器向控制台输出以下错误:
Exception thrown: 'System.FormatException' in System.Private.CoreLib.dll IdentityServer4.Validation.AuthorizeRequestValidator:Error: Invalid redirect_uri: https://localhost:44001/ { "ClientId": "myClient",
... "AllowedRedirectUris": [ "https://localhost:44001/home/claims", "https://localhost:44001/" ], "SubjectId": "anonymous", "RequestedScopes": "", "Raw": { "client_id": "myClient", "redirect_uri": "https://localhost:44001/", "response_mode": "form_post", "response_type": "code id_token", …
我已经阅读 IdentityServer4 问题线程大约一天了,但我仍然对会话/登录 cookie 过期感到困惑。
如果我像这样从客户端设置 cookie 过期(我使用 IdentityServer3 客户端和 IdentityServer4 服务器,以便启用 ASP.NET 4.x webapps 进行身份验证):
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies",
ExpireTimeSpan = new TimeSpan(10, 0, 0),
SlidingExpiration = true
});
Run Code Online (Sandbox Code Playgroud)
我可以打开 Chrome 开发人员工具 (F12) 并查看 cookie,并看到它们在浏览器关闭后立即过期(IdentityServer 的所有 cookie 的过期日期都设置为过期“1969-12-31T23:59: 59.000Z”,换言之,客户端未过期)。
无论我是否将客户端和服务器身份验证选项 UseTokenLifetime 都设置为 true,情况都是如此:
客户端:
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
...
UseTokenLifetime = true,
...
Run Code Online (Sandbox Code Playgroud)
服务器端:
services.AddAuthentication()
.AddOpenIdConnect("MyLoginScheme", "A login scheme", options =>
...
options.UseTokenLifetime = true;
...
Run Code Online (Sandbox Code Playgroud)
我不确定如何让它占用我设置的客户端 cookie 生命周期。
我一直在尝试让 Leaflet(一个网络地图 API)工作几个小时。起初我犯了一个错误,试图做太多事情,现在我只是试图让基本的例子发挥作用。
这是我的代码(HTML 和 Javascript):
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="./leaflet.js"></script>
<link rel="stylesheet" type="text/css" href="./leaflet.css" />
<script type="text/javascript">
function initmap(){
var map1 = L.map('map');
//map1.setView([38.642433, -90.255372]),9); //Thanks!
map1.setView([38.642433, -90.255372],9);
// add an OpenStreetMap tile layer
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map1);
}
</script>
<style>
#map {
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
top: 0;
z-index: 0;
}
</style>
<!-- Without this styling to set the map dimension, the tiles will get …Run Code Online (Sandbox Code Playgroud) 因此,我仍在使用Flask-mysql(请不要仅出于这个原因就不要投票……)。
我正在获取数据库上下文(mysql变量),并且可以在数据库上查询/获取结果。只是插入不起作用:它没有抱怨(抛出异常)。它True从insert方法返回。
这应该在提交时插入记录来完成,但是由于某些原因,当我用观看MySQL数据库时MySQL Workbench,表中没有插入任何内容(并且不会从insert方法中引发异常):
我将其传递给insertCmd:
"INSERT into user(username, password) VALUES ('test1','somepassword');"
Run Code Online (Sandbox Code Playgroud)
我已经检查了数据库中列的长度,并将命令复制到MySQL Workbench其中(它成功将行插入到表中)。
我很茫然。我看过的所有示例似乎都遵循这种格式,并且我具有良好的数据库上下文。您可以在评论中看到我尝试过的其他内容。
def insert(mysql, insertCmd):
try:
#connection = mysql.get_db()
cursor = mysql.connect().cursor()
cursor.execute(insertCmd)
mysql.connect().commit()
#mysql.connect().commit
#connection.commit()
return True
except Exception as e:
print("Problem inserting into db: " + str(e))
return False
Run Code Online (Sandbox Code Playgroud) cookies ×2
.net ×1
docker ×1
flask ×1
flask-mysql ×1
html ×1
javascript ×1
kubernetes ×1
leaflet ×1
mysql ×1
python ×1