我花了最近几天阅读有关OAuth2和OpenIDConnect的所有规范,并使用Thinktecture Identity Server实现测试客户端.我也遵循了几个复数课程,我认为理解它的主要要点.但是我仍然对响应类型非常困惑.
OpenIDConnect规范指定混合流响应类型是"code","id_token"和"token"的组合.我理解"id_token"允许我们最初访问基本的id信息.
我也理解代码"是指授权代码,而"令牌"是指访问令牌,并将"代码"与其他两个触发器中的一个或两个相结合,但我的理解是你交换了访问令牌的授权代码授权流程,而隐式流程隐式提供访问代码?
有人能解决我的困惑吗?
我已使用和使用"Microsoft.AspNetCore.Authentication.OpenIdConnect":"1.0.0和"Microsoft.AspNetCore.Authentication.Cookies":"1.0.0"的asp.net核心mvc应用程序配置了ASOS OpenIdConnect服务器.我已经测试了"授权代码"工作流程,一切正常.
客户端Web应用程序按预期处理身份验证,并创建一个存储id_token,access_token和refresh_token的cookie.
如何强制Microsoft.AspNetCore.Authentication.OpenIdConnect在过期时请求新的access_token?
asp.net核心mvc应用程序忽略过期的access_token.
我想让openidconnect看到过期的access_token然后使用刷新令牌进行调用以获得新的access_token.它还应该更新cookie值.如果刷新令牌请求失败,我希望openidconnect"注销"cookie(删除它或其他东西).
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AutomaticAuthenticate = true,
AutomaticChallenge = true,
AuthenticationScheme = "Cookies"
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
ClientId = "myClient",
ClientSecret = "secret_secret_secret",
PostLogoutRedirectUri = "http://localhost:27933/",
RequireHttpsMetadata = false,
GetClaimsFromUserInfoEndpoint = true,
SaveTokens = true,
ResponseType = OpenIdConnectResponseType.Code,
AuthenticationMethod = OpenIdConnectRedirectBehavior.RedirectGet,
Authority = http://localhost:27933,
MetadataAddress = "http://localhost:27933/connect/config",
Scope = { "email", "roles", "offline_access" },
});
Run Code Online (Sandbox Code Playgroud) 在与提供者进行身份验证后,应用程序通常会代表用户同时收到 ID 令牌和访问令牌。现在似乎有两种方法可以断言用户是谁。
两者似乎都是可以接受的途径,但是在某些情况下是否应该使用其中一种?
我一直在研究使用 Azure AD 为我正在构建的 API 进行 .NET Core 身份验证的基础知识,并且我一直在尝试查找有关身份验证方案的信息。我知道基于 cookie 和基于令牌的身份验证之间的区别,但在我看来 JwtBearer 和 OpenIdConnect 选项非常相似,因为它们都基于令牌系统工作。
我进行了大量搜索,但找不到任何可以解释两者之间差异的地方,在哪种情况下您会使用一种而不是另一种,甚至是这些方法的作用的定义。我在网上看了很多教程,甚至各种 YouTube 视频,其中大约 60% 使用 AddJwtBearer,其他人使用 AddOpenIdConnect 来指定他们的身份验证方案。有人能解释一下这些是做什么的,有什么区别吗?
我有一个移动应用程序(react-native)、一个资源服务(spring boot)和 Keycloak Authenticatioin Service(Auth-Service)。
客户端直接使用 Auth-Service 进行身份验证并获取访问令牌。当我向资源服务发出请求时,资源服务通过询问 Auth-Service 来检查访问令牌。但是客户端应用程序和 iss 字段获取的令牌是http://10.0.2.2:8060/auth/realms/sau和我在http://localhost:8110 的资源服务。
Keycloak 说: error="invalid_token", error_description="Invalid token issuer. Expected 'http://localhost:8060/auth/realms/sau', but was 'http://10.0.2.2:8060/auth/realms/sau'"
我的问题是如何代表我的客户在资源服务中进行身份验证?
移动应用:
export const prepareRequestBody = credentials => {
const params = new URLSearchParams();
params.append('username', credentials.username);
params.append('password', credentials.password);
params.append('client_id', "nasilim-mobile-app");
params.append('grant_type', "password");
return params;
};
export const login = credentials => {
const params = prepareRequestBody(credentials);
return axios.post(LOGIN, params);
};
Run Code Online (Sandbox Code Playgroud)
资源服务:
应用程序.yml
keycloak:
realm: sau
resource: photo-service
bearer-only: false
auth-server-url: http://localhost:8060/auth
credentials: …Run Code Online (Sandbox Code Playgroud) oauth-2.0 openid-connect keycloak keycloak-services keycloak-rest-api
我们有一个用 React 编写的 SPA 和用于托管的 ASP.net 核心。
为了验证应用程序,我们使用 IdentityServer4 并使用 cookie。客户端根据示例配置,这里描述:https : //github.com/IdentityServer/IdentityServer4/tree/main/samples/Quickstarts/4_JavaScriptClient/src
为了验证用户,一切正常。它将被重定向到登录页面。登录后,重定向到 SPA 就完成了。身份验证 cookie 按预期设置:
出于身份验证的原因,cookie 也用于其他 MVC(.net core 和 MVC 5)应用程序。在 SPA 中,我们还使用 SignalR,它需要 cookie 进行身份验证。
我们的问题:
在浏览器中闲置大约 30 分钟并进行刷新或导航后,身份验证 cookie(仅此而已,其他仍然存在)将自动从浏览器中消失。然后用户必须再次登录。为什么这会与 SPA 一起发生?
代码
完整代码可以在github中找到
客户
片段 UserService.ts
const openIdConnectConfig: UserManagerSettings = {
authority: baseUrls.person,
client_id: "js",
redirect_uri: joinUrl(baseUrls.spa, "signincallback"),
response_type: "code",
scope: "openid offline_access profile Person.Api Translation.Api",
post_logout_redirect_uri: …Run Code Online (Sandbox Code Playgroud) 我使用以下有效的代码,但是在几次成功调用(5-10)之后,我们有时会收到内部服务器错误:
req.session["oidc:accounts.rvm.com"] is undefined
我已经尝试了所有的latest开源版本。
Error: did not find expected authorization request details in session, req.session["oidc:accounts.rvm.com"] is undefined
at /opt/node_app/app/node_modules/openid-client/lib/passport_strategy.js:125:13
at OpenIDConnectStrategy.authenticate (/opt/node_app/app/node_modules/openid-client/lib/passport_strategy.js:173:5)
at attempt (/opt/node_app/app/node_modules/passport/lib/middleware/authenticate.js:366:16)
at authenticate (/opt/node_app/app/node_modules/passport/lib/middleware/authenticate.js:367:7)
at /opt/node_app/app/src/logon.js:92:7 *******
at Layer.handle [as handle_request] (/opt/node_app/app/node_modules/express/lib/router/layer.js:95:5)
at next (/opt/node_app/app/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/opt/node_app/app/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/opt/node_app/app/node_modules/express/lib/router/layer.js:95:5)
at /opt/node_app/app/node_modules/express/lib/router/index.js:281:22
Run Code Online (Sandbox Code Playgroud)
我的堆栈代码是:
at /opt/node_app/app/src/logon.js:92:7
Run Code Online (Sandbox Code Playgroud)
这是代码的结尾:
})(req, res, next); // here is line 92 but not sure if it's related
Run Code Online (Sandbox Code Playgroud)
这是完整的代码(我通过app它只是一个快速服务器):
索引.js
const express = require('express'); …Run Code Online (Sandbox Code Playgroud) 在我目前的项目中,我在一个完整的范围内使用Spring Security OAuth(http://projects.spring.io/spring-security-oauth/)项目来保护我们的资源(Web API).到目前为止一切正常.
我现在正在开发客户端,我正在寻找对身份验证方案的良好支持(因为OAuth是一种授权协议).经过漫长的互联网搜索,我很确定我应该采用OpenID Connect(http://openid.net/connect/)来满足这一要求,因为它是"OAuth 2.0之上的简单身份层"(I但是,知道在安全主题的情况下没有"简单").
可悲但真实的我在Spring Security中找不到任何有关OpenID Connect支持的好资源(不要与"纯"OpenID混淆).在https://github.com/mitreid-connect/OpenID-Connect-Java-Spring-Server上有一个OpenID Connect参考实现,但是我已经期望在Spring Security中直接提供类似的东西以及全面的文档等等.我在这里找到了大约2年的关于它的讨论https://github.com/spring-projects/spring-security-oauth/issues/220但目前的状态是什么?寻找"OpenID Connect的Spring Security支持"并没有带来任何"切实"的结果.
在Spring Security的帮助下,您是否有关于实施OpenID Connect的任何信息,文档和/或经验?
我不太明白OAuth2.0 / OIDC规范中response_type和grant_type之间的区别。
我的猜测是,在与令牌端点交互(以获取访问和/或刷新令牌)时,在 URL 中指定了grant_type,在与授权端点交互时使用response_type以获取身份令牌和授权代码。那正确吗 ?
如果是这样,在使用混合流时我们应该使用什么作为gant_type?
任何帮助将不胜感激
asp.net authentication authorization oauth-2.0 openid-connect
经过反复试验,在我看来,Google OIDC 在不提供客户端机密的情况下不支持代码流:https : //developers.google.com/identity/protocols/oauth2/native-app#exchange-authorization-code
根据 SPA 的最新最佳实践 ( https://tools.ietf.org/html/draft-ietf-oauth-security-topics-13 ),代码流 + PKCE 是处理身份验证的推荐方式。有没有人知道让 Google 的代码流接受 code_challenge 而不是 client_secret 所需的任何技巧?也许是一个虚假的秘密?
oauth-2.0 single-page-application openid-connect google-identity pkce
openid-connect ×10
oauth-2.0 ×5
asp.net ×2
asp.net-core ×2
cookies ×2
.net-core ×1
async-await ×1
javascript ×1
jwt ×1
keycloak ×1
node.js ×1
oauth ×1
passport.js ×1
pkce ×1
reactjs ×1
security ×1
spring ×1