问题标签 [pkce]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
50 浏览

openid-connect - 如何让 aspnetcore.authentication.openidconnect 使用 PKCE?

为了与给定端点(德国 DATEV)进行通信,我们的代码需要使用 PKCE(https://www.rfc-editor.org/rfc/rfc7636)。

可以连接到 OpenIdConnectEvents.OnRedirectToIdentityProvider 并计算并将“code_challenge”和“code_challenge_method”数据放入给定的 ProtocolMessage.Parameters 以传输到授权查询中。

这是使用 OpenIdConnect 启用 PKCE 的唯一方法吗?

感谢您的任何提示!

0 投票
2 回答
1051 浏览

oauth-2.0 - Snapchat 登录工具包错误:缺少 PKCE 参数

我正在尝试使用他们的登录工具包从我的应用程序登录到 Snapchat。

此代码(我更改了clientId):

生成此网址: https ://accounts.snapchat.com/accounts/oauth2/auth?client_id=45fad898-162e-48e0-8e4e-135adbc42716&redirect_uri=https%3A%2F%2Fus-central1-library-titleix.cloudfunctions.net% 2FredirectSnapchat&response_type=code&scope=https%3A%2F%2Fauth.snapchat.com%2Foauth2%2Fapi%2Fuser.display_name&state=c25hcGNoYXR0ZXN0

返回此错误: {"error":"invalid_request","error_description":"Missing PKCE parameters."}

注意: 1.redirect_uri 与 Snapchat 中列入白名单的重定向 uri 匹配 2.我正在使用开发环境 OAUTH2 CLIENT ID 3.重定向 uri 指向 Firebase 云功能。它永远不会被击中。

有什么建议么?

谢谢你,r

0 投票
1 回答
36 浏览

oauth - 本机应用程序的隐式授权

关于以下内容,我有一些事情需要澄清。“ OAuth 2.0 for Native Apps”规范说,

但是,由于隐式流不能被 PKCE [RFC7636](第 8.1 节要求)保护,因此不建议将隐式流与本机应用程序一起使用。

为什么我们不应该使用隐式授权类型背后的这个推理让我感到困惑。

据我了解,授权代码授予需要 PKCE,因为它需要 2 个单独的调用来获取访问令牌,我们需要确保这两个请求都是由同一个应用程序完成的。如果我错了,请纠正我。

现在,由于隐式授权类型不需要这样的 2 次调用来获取令牌,我认为我们真的不需要 PKCE。如果我错了,请再次纠正我。

这意味着“隐式流不需要受 PKCE 保护”。那么为什么“隐式流无法被PKCE保护”成为上述避免将其用于本机应用程序的原因呢?

0 投票
2 回答
1476 浏览

oauth-2.0 - PKCE OAuth 2.0 中“code_verifier”的意义是什么?

在 PKCE 中,我了解 code_verifier 用于生成代码质询,稍后此 code_verifier 值由授权服务器验证以完成 PKCE 过程。

这个 code_verfier 值有多敏感?这个值是否必须保密?如果这个值被泄露,对手可以执行什么攻击?

0 投票
2 回答
1344 浏览

authentication - Should I use PKCE for OpenID Connect with Native Desktop Application?

I want to use OpenID Connect for my native windows and Linux desktop applications to authenticate my users.

As stated in "OAuth 2.0 for Native Apps" Section 7.3 I want to open a local TCP port to redirect from the Authentication Server to get the Authorization Code. I think there is no other option to use for native apps which work both for Windows and Linux.

So the flow would be like:

  • Native app starts and shows login button
  • When login button is pressed
  • native apps opens a ephemeral, local port
  • browser opens with login page of authentication provider (sending along the client id and secret, redirect URI and scope openid, response_type=code)
  • After successful authentication of user in browser
  • the authenication provider redirects to the redirect URI, which is the local open port
  • the local port should display something like "close browser now and go back to app" to user
  • Native application gets code from redirect and closes port
  • Native application asks the token endpoint to get the identity token using the code
  • validate the identity token using the signature
  • will be able to get the details of the user out of that identity token

My question now is do I need PKCE? I found this article which states it does not bring any extra safety apart from making sure that when another app on the same device has registered the same Private-Use URI Scheme Redirect.

Is my plan in any other way flawed or needs further improvements? I understand that the client id and secret can be seen as "public" because they ship with the software and could be reverse engineered. But my software will not be available on public web pages (hopefully) and only be given to trusted customers (which will all have different client id and secrets).

0 投票
0 回答
457 浏览

node.js - 通过护照进行 PKCE OpenId Connect id_token 验证

我正在使用 AppAuth 通过 OpenId Connect 对用户进行身份验证,但我无法让护照做出响应,让我们一起验证令牌。

这些是在 accounts.google.com/.well-known/openid-configuration 中给出的端点: authorization_endpoint " https://accounts.google.com/o/oauth2/v2/auth " token_endpoint " https://oauth2.googleapis .com/token

passport-google-oauth20 默认为 https://accounts.google.com/o/oauth2/v2/auth https://www.googleapis.com/oauth2/v4/token

我有一个 id_token 并且我已经验证它在https://oauth2.googleapis.com/tokeninfo?id_token=XYZ工作。

https://www.googleapis.com/oauth2/v4/token?id_token=XYZ给出了一个空的响应。

我一直在尝试将 passport-google-oauth、passport-oauth2、passport-google-oauth、这些各种 google api(我提到https://openidconnect.googleapis.com/v1等?)和各种标题( JWT、Bearer 等)和 POST 参数。在每种情况下,护照的策略都会默默地失败。

我已经尝试通过中间件添加一些调试信息,如下所述: https ://dmitryrogozhny.com/blog/easy-way-to-debug-passport-authentication-in-express 它没有帮助。

看在上帝的份上,我已经对此进行了 48 小时的抨击。有人请帮忙!!!

0 投票
1 回答
1203 浏览

node.js - 我应该在哪里存储 code_verifier(使用 PKCE 的 oauth 2.0 代码授权流程)

我目前正在 SSR 页面中使用 PKCE 进行 oauth 2.0 代码授权授权(在前面使用 React,在后面使用 Express)。

code_verifier当客户端请求授权服务器代码时我应该存储在哪里(当授权服务器创建 code_challenge 和 code_verifier 以验证后者时)。我的授权服务器在独立的堆栈/基础架构中运行。

我应该存储code_verifier在 req.headers 中吗?(参见坎贝尔 OAuth TBPKCE-00 草案

我们遵循RFC6749

0 投票
1 回答
1436 浏览

azure - 有没有办法以编程方式登录到在 PKCE 流上使用带有 Cypress 的 AzureAD?

我想使用 cypress.js(https://www.cypress.io/ )来验证自己(React 应用程序)。有没有办法用 PKCE 以编程方式完成它?当我阅读和研究所有示例时-所有示例都使用隐式流

我试图使用类似https://www.npmjs.com/package/react-adal但没有成功的解决方案,因为它需要一个隐式流程turned on 我也在尝试这个:https ://xebia.com/blog/how-to-use-azure-ad-single-sign- on-with-cypress/没有成功

我希望以编程方式在 cypress 内部登录并将用户信息和 access_token 保存到 sessionStorage 以便能够执行另一个 api 调用

0 投票
1 回答
5113 浏览

reactjs - 使用 OIDC PKCE 和 identityserver.io 反应 SPA

作为学校作业,我必须做以下事情:

概述

创建一个 React SPA,它执行以下操作:

  1. 使用带有 PKCE 的授权代码流对(欢迎来到 IdentityServer4 演示站点)进行身份验证

  2. 使用正确的令牌调用(测试)

细节

在React中创建一个 SPA 。这次必须使用 React。

  • 添加一个将 OIDC 协议支持添加到 SPA 的库。确保支持带有 PKCE 的授权代码流

  • 使用(欢迎来到 IdentityServer4 演示站点)作为您的授权服务器。此授权服务器支持带有 PKCE 的授权码流

  • 使用正确的令牌调用(测试)并将结果显示给用户

  • 在 Netlify 上托管 react 应用程序

作为这个领域的初学者,我完全不明白这个作业。有人可以帮帮我吗?

0 投票
1 回答
3683 浏览

angular - 使用 angular-auth-oidc-client 使用 PKCE 代码流自动登录

我正在使用这个 npm 包通过 PKCE 代码流实现自动登录概念。我尽可能地遵循文档和示例。在我的 app.component.ts 构造函数中,我有以下内容:

在我的 ngOnInit 中,我有以下内容:

doCallbackLogicIfRequired()我的方法中:

由于登录页面(和按钮)位于身份服务器(STS 服务器)上,因此我的 Angular 应用程序中有一个自动登录组件,如下所示:

所以我的理解和基于调试流程发生如下:

  1. 用户从 STS 服务器登录并被重定向到 Angular 应用程序并立即进入应用程序组件
  2. 它在应用程序组件中做的第一件事是调用doCallbackLogicIfRequiredMethod(),然后调用authorizedCallbackWithCode()方法。
  3. 然后它转到(应用程序组件的)ngOnInit,它检查用户是否被授权,并且由于我们是第一次登录,他/她不是,所以它路由到自动登录组件,该组件调用oidcSecurityService.authorize()方法。

所以,现在这是我遇到一些问题的地方,不确定发生了什么。

  1. 因此,在调用该oidcSecurityService.authorize() 方法(int the auto-login.component)后,它立即进入getIsAuthorized()位于应用程序组件 ngOnInit 中的方法的订阅主体。为什么要这样做?是什么导致它getIsAuthorized()再次击中?

以下是问题:

  1. getIsAuthorized()方法被多次命中,并且由于某种原因,它总是错误的,即使在authorize()从自动登录组件调用该方法之后也是如此。
  2. 当我打开静音更新时,它似乎使事情变得更糟,并且调用的 getIsAuthorized()次数更多。

发生这种情况后,身份服务器出现了所有奇怪的问题/错误,我认为这是因为这种getIsAuthorized()方法,也许是我对实际使用它的地点和时间的理解。

问题:

  1. 为了通过自动登录实现此流程,我是否根据我的示例代码采取了正确的方法?
  2. 有人可以解释何时getIsAuthorized()应该调用订阅吗?库中的其他方法是否可能在幕后调用它,这就是为什么它被我多次调用的原因?
  3. 我似乎遇到了间歇性错误 -无效的随机数无效的状态,为什么会发生这种情况(我读到当authorize()方法被多次调用时可能会发生这种情况,但我在 auto-login.component 中只有一次调用它)?
  4. 只是为了我的理智,所以我可以更好地理解流程, authorizedCallbackWithCode()它去哪里的方法的目的是什么,它是否返回到任何地方(是否有我应该订阅的事件处理程序)?
  5. 静默更新逻辑也应该调用该authorize()方法吗?似乎在幕后某处这样做 - 我注意到在我调用authorize()方法之前(从自动登录组件), authorizationResultComplete事件处理程序被触发,而我从来没有调用authorize(). 这是静默更新的预期行为吗,如果这样做会破坏我的应用程序,我认为它应该在幕后(静默)做所有事情吗?

我一直在努力解决这个问题,如果有人使用 angular 2+ 和这个库成功地实现了这个流程,任何帮助都将不胜感激。

谢谢你!