как обойти пользовательский логин auth0 при использовании кипариса - PullRequest
0 голосов
/ 28 января 2020

Привет, я пытаюсь создать автоматический c логин, используя кипарис с auth0. тем не менее, я не могу войти, я прошел эти две статьи и на основании этого я попытался изменить свой сценарий. Я могу получить токен с сервера авторизации, но мой URL-адрес обратного вызова не запускается. Я буду признателен, если кто-нибудь сможет мне помочь. это статьи: [title] https://blog.johnnyreilly.com/2018/07/cypress-and-auth0.html и [titile] https://auth0.com/blog/end-to-end-testing-with-cypress-and-auth0/ вот код

const auth0 = require('auth0-js');

Cypress.Commands.add('loginAsAdmin', (overrides = {}) => {
  Cypress.log({
    name: 'loginAsAdminBySingleSignOn',
  });

  const webAuth = new auth0.WebAuth({
    domain: 'mydomain from auth0',
    responseType: 'token id_token',
    redirectUri: 'APP_URL/callback',
    clientID: 'clientId from auth0',
  });
  //cy.debug();
  webAuth.client.login(
    {
      realm: 'Username-Password-Authentication',
      username: 'app_username',
      password: 'app_password',
      //audience: 'domain/userinfo', //commented out is this the right one or the one below
      audience: 'domain/api/v2/',
      scope: 'openid',
    },
    function(err, authResult) {
      // Auth tokens in the result or an error
      console.log(authResult);
      if (authResult && authResult.accessToken && authResult.idToken) {
        /*const token = {
          my_access_token: authResult.accessToken,
          my_id_token: authResult.idToken,
          // Set the time that the access token will expire at
          my_expires_at:
            authResult.expiresIn * 1000 + new Date().getTime(),
        }; */
        //console.log(authResult);
        const {
          accessToken: my_access_token,
          idToken: my_id_token,
          expiresIn,
        } = authResult;

        // to increase the expiry time
        const my_expires_at = expiresIn * 1000 + new Date().getTime();

        //setting needed cookie for application but cookie not set in application
        //I don't know what is wrong
        cy.setCookie('my_access_token', my_access_token, {
          log: true,
          domain: 'jolt.workbench.adarga.ai',
        });
        cy.setCookie('my_id_token', my_id_token);
        cy.setCookie('my_expires_at', my_expires_at);

        // to confirm the variables have value but why is cookie not being set above
        console.log(my_access_token, 'yes');
        console.log(my_id_token, 'me');
        console.log(my_expires_at, 'that');



        /*window.sessionStorage.setItem(
          'my-super-duper-app:storage_token',
          JSON.stringify(token),
        );
        cy.request('/callback'); */
      } else {
        console.error('Problem logging into Auth0', err);
        throw new Error();
      }
    },
  );
});

Cypress.Commands.add('visitHome', (overrides = {}) => {
  cy.visit('/');
  cy.getCookies({ log: true });
  cy.log('YES');
});

Test

describe('login via api', () => {
  it('should successfully log into adarga bench', () => {
    cy.visitHome().loginAsAdmin();
    //cy.visit('/');
  });
});
...