vendredi 8 février 2019

ember-simple-auth and Implicit Grant authentication: use authenticateSession test helper

If a User is not authenticated, I redirect him to a corporate login page:

https://super-secret-gateway/authorization.oauth2?client_id=XXXX&redirect_uri=http://localhost:4200/callback&response_type=token&scope=profile%20openid

Once he is authenticated after entering his username and password, he is redirected back with the following URL

https://myapp/callback#access_token=2YotnFZFEjr1zCsicMWpAA&type=Bearer&expire_in=3600&state=myAppRandomState

I can't figure out how to use authenticateSession test helper in this case. The ESA docs have no detailed example about that and the way I do it is not working:

module('Acceptance | Dashboard', function(hooks) {
  setupApplicationTest(hooks);
  setupMirageTest(hooks);

  test('Authenticated users can visit /dashboard', async function(assert) {
    let shop = this.server.create('shop');
    this.server.create('user', { shop });

    await authenticateSession({
      token: 'abcdDEF',
      token_type: 'Bearer'
    });

    await visit('/dashboard');

    assert.equal(currentURL(), '/dashboard', 'user is on dashboard page');
  });
});

What am I missing ? Thank you.




Aucun commentaire:

Enregistrer un commentaire