【问题标题】:Strongloop REST API: change passwordStrongloop REST API:更改密码
【发布时间】:2015-11-13 03:02:29
【问题描述】:

我想实现一个简单的“更改密码”,以便授权用户可以这样做。 通过使用资源管理器进行试验,我设法为用户模型(我对默认用户的扩展)编写了一个 ACL,允许用户更改其数据:

{
      "principalType": "ROLE",
      "principalId": "$owner",
      "accessType": "WRITE",
      "permission": "ALLOW"
}

但是,当我从资源管理器尝试使用新凭据的端点 PUT /users/{id} 时,它会静默失败,即它返回 ok,但不执行密码更改:

请求:

http://localhost:3000/api/users/6?access_token=6CVOuMZCLB8deH7e5t8xJtzDlWjU98WUCRCSGO6zdjW0bhSR6Z20vddl7dIWepF8

数据:

{

  "credentials":
    {"email":"pepito@example.com", "password": "ppito"}

}

(用户 6 已通过身份验证)。

回应:

{
  "realm": null,
  "username": "pepito",
  "credentials": {
    "email": "pepito@example.com",
    "password": "ppito"
  },
  "challenges": null,
  "email": "pepito@example.com",
  "emailVerified": true,
  "verificationToken": "2a9c25fa6e858db5894f98cd3f0be3694041f148781896cb5775ff30da1f367c7843ac4b60013fd47c34c6f1a862a5cabb77cf2807c101da7f2acfcdd8853ec7",
  "status": null,
  "created": null,
  "lastUpdated": null,
  "id": 6
}

但是,密码保持不变(尝试从资源管理器注销/登录)。

你能帮我吗?

【问题讨论】:

    标签: rest authentication strongloop


    【解决方案1】:

    处理密码是不同的游戏。要更改密码,请使用以下代码:

    var AccessToken = Customer.app.models.AccessToken;
            AccessToken.findById(access_token, function (err, token) {
                if (err) cb(err);
                else {
                    Customer.findById(token.userId, function (err, user) {
                        if (err) {
                            cb(err);
                        }
    
                        if (user == null || user == undefined) cb(new Error('user is undefined'));
    
                        user.updateAttribute('password', password, function (err, user) {
                            if (err) {
                                cb(err);
                            }
    
                            cb(null, 'success');
                        });
                    });
                }
            })
    

    updateAttribute 允许您进行更新。

    我一直无法从 swagger 中更改密码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-22
      相关资源
      最近更新 更多