我尝试让OpenID Connect运行...我的Web API用户设法获得OpenID Connect Provider的授权码.我应该如何将此代码传递给我的ASP.NET Web API?如何配置OWIN中间件,以便我可以使用授权码获取访问令牌?
更新:SPA使用AJAX与我的Web服务(ASP.NET Web API)进行通信.在我的Web服务中使用OWIN Middleware.我将OpenIDConnect设置为身份验证机制.首次调用Web服务时,它成功将用户重定向到OpenID Connect Provider的登录页面.用户可以登录并获得授权码.AFAIK此代码现在可以(通过我的Web服务)用于访问令牌.但是,我不知道如何将此代码返回到我的Web服务(这是使用标头完成吗?)然后配置什么来获取访问令牌.我想我可以手动调用令牌端点,但我想利用OWIN组件.
我有一个ASP.NET MVC 5应用程序,可以对Azure Active Directory进行身份验证.我希望在整个应用中启用SSL.因此利用全球过滤器如下:
public class FilterConfig
{
/// <summary>
/// Registers the global filters.
/// </summary>
/// <param name="filters">The filters.</param>
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new RequireHttpsAttribute());
}
}
Run Code Online (Sandbox Code Playgroud)
在此之后,我还将项目属性中的"启用SSL"设置为true.这给了我以下SSL URL - > https:// localhost:34567.我将项目更新为在"项目URL"中"服务器"下的"Web选项卡"下的IIS Express路径中.但是在运行该站点时,我遇到以下错误:
IDX10311:RequireNonce为'true'(默认值),但validationContext.Nonce为null.nonce无法验证.如果您不需要检查nonce,请将OpenIdConnectProtocolValidator.RequireNonce设置为"false".
我有认证.在网站上启用.我使用Azure Active目录.
安全代码如下:
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = authority,
PostLogoutRedirectUri = postLogoutRedirectUri
});
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Audience = audience,
Tenant = tenant,
});
Run Code Online (Sandbox Code Playgroud)
认证.正在从web.config中读取值,如下所示:
<add key="ida:ClientId" value="<some_guid>" />
<add key="ida:Audience" value="https://localhost:34567/" />
<add key="ida:AADInstance" …Run Code Online (Sandbox Code Playgroud) 我正在尝试升级我的MVC网站以使用新的OpenID Connect标准.OWIN中间件看起来非常强大,但不幸的是只支持"form_post"响应类型.这意味着Google不兼容,因为它会在"#"后面的URL中返回所有令牌,因此它们永远不会到达服务器并且永远不会触发中间件.
我试图在中间件中自己触发响应处理程序,但这似乎根本不起作用,所以我有一个简单的javascript文件解析返回的声明并将它们发送到控制器动作进行处理.
问题是,即使我在服务器端获取它们,我也无法正确解析它们.我得到的错误看起来像这样:
IDX10500: Signature validation failed. Unable to resolve
SecurityKeyIdentifier: 'SecurityKeyIdentifier
(
IsReadOnly = False,
Count = 1,
Clause[0] = System.IdentityModel.Tokens.NamedKeySecurityKeyIdentifierClause
),
token: '{
"alg":"RS256",
"kid":"073a3204ec09d050f5fd26460d7ddaf4b4ec7561"
}.
{
"iss":"accounts.google.com",
"sub":"100330116539301590598",
"azp":"1061880999501-b47blhmmeprkvhcsnqmhfc7t20gvlgfl.apps.googleusercontent.com",
"nonce":"7c8c3656118e4273a397c7d58e108eb1",
"email_verified":true,
"aud":"1061880999501-b47blhmmeprkvhcsnqmhfc7t20gvlgfl.apps.googleusercontent.com",
"iat":1429556543,"exp\":1429560143
}'."
}
Run Code Online (Sandbox Code Playgroud)
我的令牌验证码遵循开发IdentityServer的优秀人员概述的示例
private async Task<IEnumerable<Claim>> ValidateIdentityTokenAsync(string idToken, string state)
{
// New Stuff
var token = new JwtSecurityToken(idToken);
var jwtHandler = new JwtSecurityTokenHandler();
byte[][] certBytes = getGoogleCertBytes();
for (int i = 0; i < certBytes.Length; i++)
{
var certificate = new X509Certificate2(certBytes[i]); …Run Code Online (Sandbox Code Playgroud) 我了解Google Play测试版功能允许我将APK分发给封闭的用户组,但我还需要能够验证使用Google登录下载后登录的用户是否也在我的应用的测试版程序中,以便确保APK不是在我不知情的情况下分发和使用的.
有没有办法检查Google登录用户是否参与了使用OpenID Connect或类似技术的beta测试?
谢谢!
scopeOpenID Connect、JWT 或 OAuth 中是否有任何标准声明?
在IdentityServer 4 文档中,有一个“范围”,它是一个空格分隔的字符串。
{
"client_id": "mobile_app",
"sub": "123",
"scope": "read write delete"
}
Run Code Online (Sandbox Code Playgroud)
但从我的 IdentityServer 4 实例中,我在访问令牌中得到了一个“范围”声明,它是一个字符串数组。
{
// ...
"client_id": "mobile_app",
"sub": "123",
"scope": [ "openid", "profile", "email", "offline_access" ],
"amr": [ "pwd" ]
}
Run Code Online (Sandbox Code Playgroud)
在OpenID Connect Core 1.0规范中,我没有看到“范围”被列为声明。在RFC 7519 JSON Web Token (JWT) 规范中,我没有看到“范围”被列为声明。
带有 Spring Security 5 的 Spring Boot 2 可以配置为使用 openID 连接 ID 提供程序进行身份验证。我仅通过配置 Spring Security 就设法设置了我的项目 - 这适用于各种完美预配置的安全机制,例如缓解会话固定。
但是似乎 Spring Security 在令牌过期时不会自行刷新令牌(存储在会话中)。
是否有设置或我必须自己照顾刷新?
更新:Spring Boot 2.1 已经发布,所以是时候重新审视这个问题了。我仍然不知道 accessToken 现在是否可以自动刷新,或者我是否必须为此编写代码......
尝试获取访问令牌以在我的 WebApi 中使用 MS Graph。但不断收到这个错误,
[TaskCanceledException: 一个任务被取消。] System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +167。.
[IOException: IDX20804: 无法从以下位置检索文档:'[PII is hidden]'。] Microsoft.IdentityModel.Protocols.d__8.MoveNext() +662 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99。. [InvalidOperationException: IDX20803: 无法从以下位置获取配置:'[PII is hidden]'。] Microsoft.IdentityModel.Protocols.d__24.MoveNext() +1586 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
尝试了我可以在网上找到的所有修复程序。
我使用这个repo作为 auth 部分的参考。
我怎样才能解决这个问题?
我一直在研究使用 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
我使用以下有效的代码,但是在几次成功调用(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) openid-connect ×10
jwt ×4
c# ×3
owin ×3
.net ×1
.net-core ×1
android ×1
asp.net-mvc ×1
async-await ×1
azure ×1
beta-testing ×1
google-play ×1
javascript ×1
keycloak ×1
node.js ×1
nonce ×1
oauth-2.0 ×1
passport.js ×1
ssl ×1