简体   繁体   English

Azure B2C - 无法从策略中的 JWT 客户端断言令牌读取“日期”声明

[英]Azure B2C - Not able to read "Date" Claim from JWT client assertion token in policy

I'm not able to read date claim from JWT client assertion token and then transform into "datetime" claim by transformation method "ConvertDateToDateTimeClaim".我无法从 JWT 客户端断言令牌读取日期声明,然后通过转换方法“ConvertDateToDateTimeClaim”转换为“日期时间”声明。 I've tried below date formats in claim but none works.我在声明中尝试了以下日期格式,但没有任何效果。 It works as excepted, When I set Default values of Date claim in B2C policy.当我在 B2C 策略中设置日期声明的默认值时,它作为例外工作。

JWT Token: { "createdDate1": "2019-05-26", "createdDate2": "2019-05-26T00:00:00", "createdDate3": "2019-05-26T00:00:00Z", "verifiedEmail": "xxxxxxxxxxxxxxx", "nbf": 1560005928, "exp": 1560006228, "iss": "xxxxxxxxxxxxxxxxxxxx", "aud": "xxxxxxxxxxxxxxxxxxxxx" } JWT 令牌:{ "createdDate1": "2019-05-26", "createdDate2": "2019-05-26T00:00:00", "createdDate3": "2019-05-26T00:00:00Z", "verifiedEmail ": "xxxxxxxxxxxxxxx", "nbf": 1560005928, "exp": 1560006228, "iss": "xxxxxxxxxxxxxxxxxxxx", "aud": "xxxxxxxxxxxxxxxxxxxxx" }

Error: The data type 'String' of the claim with id 'createdDate' does not match the DataType 'Date' of ClaimType with id 'createdDate' specified in the policy.错误:ID 为“createdDate”的声明的数据类型“String”与政策中指定的 ID 为“createdDate”的 ClaimType 的数据类型“Date”不匹配。

B2C Policy B2C 政策

Help required.需要帮助。

There was a bug trying to read a dateTime claim from the JWT in the id_token_hint parameter.尝试从 id_token_hint 参数中的 JWT 读取 dateTime 声明时存在错误。 It got fixed this week.这周就修好了。 I could imagine it is the same with a date claim.我可以想象它与日期声明相同。

I create a JWT with the following claim:我创建了一个具有以下声明的 JWT:

DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
new System.Security.Claims.Claim("LinkExpirationDateTime", ((long)(DateTime.UtcNow.AddMinutes(_appSettings.LinkExpiresAfterMinutes) - unixEpoch).TotalSeconds).ToString(), System.Security.Claims.ClaimValueTypes.DateTime, issuer)

You can read it like shown in some samples on https://github.com/azure-ad-b2c/samples/ ("Email delivered account redemption link" for example).您可以像https://github.com/azure-ad-b2c/samples/上的一些示例中所示那样阅读它(例如,“电子邮件提供的帐户兑换链接”)。 The ClaimType would be: ClaimType 将是:

<ClaimType Id="LinkExpirationDateTime">
    <DisplayName>LinkExpirationDateTime</DisplayName>
    <DataType>dateTime</DataType>
</ClaimType>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM