【问题标题】:Auth0 password reset errorAuth0 密码重置错误
【发布时间】:2017-08-02 04:14:16
【问题描述】:

我正在使用 Angular 2 和锁定版本 10.8,并且我正在尝试为用户添加更改密码的功能。我试过下面的方法,调用Management API,其中参数user_id是从用户的Auth0配置文件接收到的user_id,参数connection'Username-Password-Authentication'

public resetPassword(user_id: string, password: string, connection: string): Observable<any> {        
    let body = JSON.stringify({ password, connection });
    let headers = new Headers({ 'Content-Type': 'application/json' });
    let options = new RequestOptions({ headers: headers });        
    return this.authHttp.patch('https://https://manage.auth0.com/api/v2/users/' + user_id, body, options).map(response => {
        return response.json();
    }).catch(this.appService.handleError);
}

使用此代码时,我收到以下错误:

选项 https://https//manage.auth0.com/api/v2/users/auth0%7C58b77f281667c9685d1019c3 网络::ERR_NAME_NOT_RESOLVED

我在这里做错了什么?

这是我使用的两个来源:
https://auth0.com/docs/connections/database/password-change https://auth0.com/docs/api/management/v2#!/Users/patch_users_by_id

是的,“更改密码流程 v2”切换已启用。

【问题讨论】:

    标签: angular auth0


    【解决方案1】:

    替换'https://https://manage.auth0.com/api/v2/users/'

    'https://manage.auth0.com/api/v2/users/'

    在您的补丁请求中。

    该协议在 url 中重复了两次。

    编辑

    您还需要将“管理”替换为您的 Auth0 帐户名称 https://&lt;account&gt;.auth0.com/api/v2/users/

    您可以前往https://manage.auth0.com/#/apis,单击Auth0 Management API 链接并在“设置”中的identifier 字段。这应该是您请求的基本 URL。

    还要确保在 Auth0 仪表板的客户端设置中检查 http://localhost:3000 是否位于 Allowed Origins (CORS) 字段中。

    【讨论】:

    • 我想知道这一点,但文档实际上像我一样有两次“https”。诡异的。也许是他们的错字?无论如何,我进行了更改,现在我在 OPTIONS 请求方法上得到了 401(未经授权)。它还说“对预检请求的响应未通过访问控制检查:请求的资源上不存在'Access-Control-Allow-Origin'标头。因此不允许访问源'localhost:3000'。响应具有HTTP状态码 401。”
    • 是的,这很可能是文档中的拼写错误。有关您遇到的错误,请参阅我编辑的答案。
    • 一开始用错了账号。解决了这个问题,现在我收到了 403(禁止)
    • 我认为这里的问题可能出在您的 SPA 中。它可能需要在管理 api 受众上声明额外的 scopes,例如 update:users。这可能会给您的应用带来一些安全问题。您不想使用password reset email 是否有特定原因?在这种情况下,我会考虑将密码重置逻辑移动到服务器并使用 client credentials 访问管理 API
    猜你喜欢
    • 2016-12-22
    • 1970-01-01
    • 2016-07-11
    • 2022-01-01
    • 2016-06-15
    • 2013-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多