如上所述,devise_token_auth有三个API调用来重置密码。
1. POST调用发送密码时应重置电子邮件
POST /auth/password
Params: 'email', 'redirect_url'
如:
curl -v -H 'Content-Type: application/json' -H 'Accept: application/json' -X POST https://myapp.com/auth/password -d '{"email":"[email protected]", "redirect_url": "https://myapp.com/auth/sign_in"}'
注意,鉴于redirect_url
必须对应于您希望用户采取确认和端点重置他们的密码。
E.g.如果想要重定向到iOS应用程序中的某个位置,请在redirect_url
定义中使用该应用程序方案的URL。例如。手动执行此操作在iOS上:
curl -v -H 'Content-Type: application/json' -H 'Accept: application/json' -X POST https://myapp.com/auth/password -d '{"email":"[email protected]", "redirect_url": "myappStoreAppName://auth/password/edit"}'
2. get调用来验证密码重置令牌(点击电子邮件)
GET /auth/password/edit
Params: 'password_reset_token', 'redirect_url'
E.g. via our iOS app would produce an email link like this: https://myapp.com/auth/password/edit?config=default&redirect_url=myappStoreName%3A%2F%2Fauth%2Fpassword%2Fedit&reset_password_token=Qv6mkLuoy9zN-Y1pKghB
如果这是从一个Web应用程序中,“redirect_to的”链接应该指向可以填写password
和password_confirmation
表格的表格。如果密码重置电子邮件链接指向移动应用程序,则取决于该应用程序以创建密码重置表单。
在这一步最重要的是知道发出请求的客户端将从Rails应用程序获取Access-Token
HEADER。
此Access-Token需要保存,因为这是客户端将在下一个请求中使用的内容,以保证用户在用户更改密码时进行身份验证。
3. PUT调用来更新用户的密码
PUT /auth/password
Head: 'uid: VALUE', 'client: VALUE', 'access-token: VALUE', 'token-type: Bearer'
Params: 'password', 'password_confirmation'
注意,需要为这个PUT通话将被提供的水头值。这些确保我们(现在通过身份验证的用户)有权执行密码更改,并确保我们的用户即使在更改密码后仍能继续保持身份验证状态。
E.g.通过卷曲:
curl -v -H 'Content-Type: application/json' -H 'uid: [email protected]' -H 'client: U9FIDbiDbYVulsi1dBpxOQ' -H 'access-token: JbGQi97FTAwsW4n6SZ9aYQ' -H 'Accept: application/json' -X PUT https://myapp.com/auth/password -d '{"password": "foobar", "password_confirmation": "foobar"}'
我已经失去了整整一天,我会很感激这个指导。 – Kelseydh