简体   繁体   English

Azure AD B2C 在客户端凭据的 /oauth2/v2.0/token 端点中缺少随机数

[英]Azure AD B2C missing nonce in /oauth2/v2.0/token end point for client credentials

I have an API which is using Azure AD B2C for authentication and on success returning access_token .我有一个 API,它使用 Azure AD B2C 进行身份验证并成功返回access_token Request is as follows:请求如下:

POST /{tenant}/oauth2/v2.0/token        
Host: login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded

client_id={client-id}
&scope=https://{tenant}/{app_id}/.default
&client_secret=sampleCredentia1s
&grant_type=client_credentials

But when I pass nonce as a query parameter, it is not returning in JWT token.但是当我将 nonce 作为查询参数传递时,它不会在 JWT 令牌中返回。 Can you please share how to return a nonce in access_token for validating token against token replay attacks?你能分享一下如何在access_token返回一个 nonce 来验证令牌对抗令牌重放攻击吗?

• You are right that the nonce is a strategy used to mitigate token replay attacks. • 您是对的,nonce 是一种用于缓解令牌重放攻击的策略。 Your application can specify a nonce in an authorization request by using the nonce query parameter.您的应用程序可以使用 nonce 查询参数在授权请求中指定一个 nonce。 The value you provide in the request is emitted unmodified in the nonce claim of an ID token only.您在请求中提供的值仅在 ID 令牌的 nonce 声明中未经修改地发出。 This claim allows your application to verify the value against the value specified on the request.此声明允许您的应用程序根据请求中指定的值验证该值。 Your application should perform this validation during the ID token validation process.您的应用程序应在 ID 令牌验证过程中执行此验证。 Thus, the nonce value is typically a randomized, unique string that can be used to identify the origin of the request.因此,nonce 值通常是一个随机的、唯一的字符串,可用于标识请求的来源。

• Also, the nonce will be returned in the id_token and you can validate it when you decode and validate the id_token. • 此外,nonce 将在 id_token 中返回,您可以在解码和验证 id_token 时对其进行验证。 But state is returned in the response, not in the token.但是状态是在响应中返回的,而不是在令牌中。 Also, nonce should be validated at the client side.此外,应该在客户端验证随机数。 Please note that the generated nonce must be persisted in your web application using any of the following methods, ie, HttpOnly session cookie and HTML5 local storage value.请注意,生成的随机数必须使用以下任何一种方法保存在您的 Web 应用程序中,即 HttpOnly 会话 cookie 和 HTML5 本地存储值。

 Example --> ‘ window.localStorage.setItem('nonce', randomString(16)); ‘

The nonce parameter value needs to include per-session state and be unguessable to attackers. nonce 参数值需要包含每个会话的状态,并且攻击者无法猜测。 To achieve this for Web Server Clients, you need to store a cryptographically random value as an HttpOnly session cookie and use a cryptographic hash of the value as the nonce parameter.要为 Web 服务器客户端实现这一点,您需要将加密随机值存储为 HttpOnly 会话 cookie,并使用该值的加密哈希作为 nonce 参数。 In that case, the nonce in the returned ID Token is compared to the hash of the session cookie to detect ID Token replay by third parties.在这种情况下,将返回的 ID 令牌中的随机数与会话 cookie 的哈希值进行比较,以检测第三方对 ID 令牌的重放。 A related method applicable to JavaScript Clients is to store the cryptographically random value in HTML5 local storage and use a cryptographic hash of this value shown as above.一种适用于 JavaScript 客户端的相关方法是将加密随机值存储在 HTML5 本地存储中,并使用该值的加密哈希,如上所示。

• For validating the ID_token, find the below parameters passed in the application where the token must be validated and decoded as usual. • 为了验证 ID_token,找到应用程序中传递的以下参数,其中必须像往常一样验证和解码令牌。 Its nonce claim must contain the exact same value that was sent in the request: -它的 nonce 声明必须包含与请求中发送的完全相同的值:-

      ‘ var jwt = '...'; // validated and decoded ID Token body
       if (jwt.nonce === window.localStorage.getItem('nonce')) {
              // Nonce is OK
        } else {
         // Nonce is not OK! Token replay attack might be underway
       } ‘

Please find the below example of the implicit flow containing nonce and state as a parameter of the request that would be sent by the user to the Authorization Server in response to a corresponding HTTP 302 redirect response by the Client: -请找到以下隐式流示例,其中包含 nonce 和 state 作为请求的参数,该请求将由用户发送到授权服务器以响应客户端的相应 HTTP 302 重定向响应:-

    ‘ GET /authorize?
    response_type=id_token%20token
    &client_id=s6BhdRkqt3
    &redirect_uri=https%3A%2F%2Fclient.example.org%2Fcb
    &scope=openid%20profile
    &state=af0ifjsldkj
    &nonce=n-0S6_WzA2Mj HTTP/1.1
    Host: server.example.com ‘

Also, find the below example of the authorization request sent in the browser URL using nonce as a parameter: -另外,找到以下使用 nonce 作为参数在浏览器 URL 中发送的授权请求示例:

  ‘ https://${yourDomain}/oauth2/default/v1/authorize?client_id=0oabv6kx4qq6
     h1U5l0h7&response_type=id_token 
      token&scope=openid&redirect_uri=https%3A%2F%2Fwww.example.com&state=state- 
      296bc9a0-a2a2-4a57-be1a-d0e2fd9bb601&nonce=foo ‘

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 404 未找到 Azure AD B2C 的 oauth2/v2.0/token 端点 - 404 Not Found for oauth2/v2.0/token endpoint of Azure AD B2C 在 Azure AD b2b 中使用我自己的域自定义域 https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token - Customize domain with my own domain in Azure AD b2b https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token Azure AD B2C -> OAuth2 -> Azure Function App Token Exchange - Azure AD B2C -> OAuth2 -> Azure Function App Token Exchange Spring OAuth2客户端:oauth2 / v2.0 / token的POST请求上的I / O错误 - Spring OAuth2 Client: I/O error on POST request for oauth2/v2.0/token Azure B2C访问令牌NULL春季OAuth 2.0 - Azure B2C Access Token NULL Spring OAuth 2.0 Azure AD B2C:: 访问令牌中缺少角色声明 - Azure AD B2C :: Roles claim is missing in access token Azure B2C OAuth 客户端凭证流中的访问令牌声明中缺少 Scope - Scope missing in access token claims in Azure B2C OAuth Client credential flow Azure B2C Userflow v2.0(注册和登录) - 无法找到 Userinfo 端点 - Azure B2C Userflow v2.0(SignUp and SignIn) - unable to find Userinfo endpoint Azure AD v2.0使用令牌进行MobileApp身份验证 - Azure AD v2.0 using the token for MobileApp authentication 使用OAuth2 Provider的Azure AD B2C社交登录 - Azure AD B2C social sign-in with OAuth2 Provider
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM