【问题标题】:Programmatically authenticate in Auth0在 Auth0 中以编程方式进行身份验证
【发布时间】:2018-10-12 14:20:15
【问题描述】:

我正在设置 cypress.io 来测试一个 React 应用。我正在尝试使用 Auth0 Lock 以编程方式进行身份验证,因此我不必测试他们的 UI。步骤如下:

  1. 发布到https://[auth0-domain].com/usernamepassword/login

     client_id: "",
     client_secret: "",
     audience: "audience",
     redirectUri: "http://[auth0-domain].com:8383/callback",
     scope: "openid email crud:all",
     protocol: "oauth2",
     sso: true,
     username: "",
     password: "",
     connection: "conn",
     tenant: "tenant",
     popup: false,
    
  2. 收集返回的表单数据

  3. 发布到https://[auth0-domain].com/login/callback

    wa=wsignin1.0&wresult=token&wctx=metastuff

第一步有效,但在第三步中,我可以发布到登录/回调,但我得到一个带有以下错误消息的 HTML 页面:

Looks like something went wrong! There could be a misconfiguration in the system or a service outage. We track these errors automatically, but if the problem persists feel free to <a href="https://auth0.com/support" target="_new">contact us</a> with this tracking id: <b>e88e08e43b7cdee78458</b>.<br/>Please try again.

我想知道 Auth0 是否有什么东西阻止了我这样做,或者我没有发送正确的数据/标头。

【问题讨论】:

    标签: auth0 cypress auth0-lock


    【解决方案1】:

    我最终使用了调用 auth0 回调的 auth0-js 模块。然后我使用 'should' 等待 localStorage 被设置:

    import auth0 from 'auth0-js';
    import url from 'url';
    
    Cypress.Commands.add('login', () => {
      const auth = new auth0.WebAuth({
        audience: 'http://audience',
        domain: 'domain.auth0.com',
        clientID: 'qqqqqqqqqqqq',
        redirectUri: 'http://localhost/callback',
        responseType: 'token id_token',
        scope: 'openid email profile name username groups roles',
        sso: true
      });
    
      auth.login({username: 'username', password: 'pass'});
      cy.window().its('localStorage.user_profile').should('exist')
    });
    

    【讨论】:

    • 你弄清楚为什么你原来的步骤不起作用了吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-05
    • 2015-01-08
    相关资源
    最近更新 更多