前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SAP 电商云 Spartacus UI userID 即邮件地址中的加号问题

SAP 电商云 Spartacus UI userID 即邮件地址中的加号问题

作者头像
Jerry Wang
发布2022-09-23 19:47:14
5060
发布2022-09-23 19:47:14
举报

如果用户登录名或密码包含符号 +,它将被替换为空格,因为 Content-Type 等于 application/x-www-form-urlencoded。

下面是一个例子:

https://:9002/occ/v2/electronics-spa/forgottenpasswordtokens?lang=en&curr=USD

我输入了包含 + 号的邮件地址后,点击 Submit,发送一个 HTTP POST 请求到后台,响应为 202:

从 Form Data 区域,我们可以发现,这个 userId 显示为 a @sap.com, 邮箱地址里包含了空格符号:

找到 Reset Password Component 的 selector:cx-forgot-password

Component 名称为:ForgotPasswordComponent

通过 Service 实现:

依赖于 UserPasswordFacade:

调用 userProfileConnector 完成:

connector 调用 userProfileAdapter:

这是一个 abstract class,我们调用 OCCUserProfileAdapter 实现:

OccUserProfileAdapter 最终调用 HTTP Client 的 post 操作:

我们在后台打印 Angular HTTP client 发送过来的请求,发现确实 + 号被转换成了空格:

https://github.com/angular/angular/blob/8.2.4/packages/common/http/src/params.ts#L81

这个文件首先使用浏览器的 encodeURIComponent() 方法,但随后恢复了几个字符的编码,包括 + 号。

一种比较合理的设计是:

感谢@meeque 参与讨论这个话题。 Angular 确实不支持干净的编码/解码,这就是为什么我们没有为各种字符(@😒,;+=?/)获得正确的编码。 我浏览了与此主题相关的各种资源,但我不确定为什么会跳过这些字符。

  • 实现一个仅使用来自浏览器的 encodeURIComponent 和 decodeURIComponent 的 HttpParameterCodec
  • 在我们使用 HttpParameters 的任何地方都使用编码器,但至少在创建用户和密码方面
  • 允许通过 DI 或通过在配置模块中配置类来覆盖此行为

可以先在前台进行 encode:

代码语言:javascript
复制
const pass = encodeURIComponent(password.value);
this.auth.authorize(userId.value.toLowerCase(), pass);

然后在 Hybris 后台 decode:

代码语言:javascript
复制
if (credential instanceof String) {
    // if credential is a string use URLDecode class. 
    credential = URLDecoder.decode(String.valueOf(credential), StandardCharsets.UTF_8);
    if (!user.checkPassword((String) credential)) {
        throw new BadCredentialsException(this.messages.getMessage("CoreAuthenticationProvider.badCredentials", "Bad credentials"));
    }
} else {
    if (!(credential instanceof LoginToken)) {
        throw new BadCredentialsException(this.messages.getMessage("CoreAuthenticationProvider.badCredentials", "Bad credentials"));
    }
   if (!user.checkPassword((LoginToken) credential)) {
       throw new BadCredentialsException(this.messages.getMessage("CoreAuthenticationProvider.badCredentials", "Bad credentials"));
     }
}

后续修复进度,请跟踪这个 Github issue.

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2022-09-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档