jeudi 11 février 2016

authenticating with ember-simple-auth and torii custom authenticator

I'm getting different behaviours from session.isAuthenticated depending on how I access it. This is probably only a symptom of my real problem.

What happens:

  1. click sign in button
  2. window pops up, prompts for login
  3. login, popup goes away
  4. templates that rely on session.isAuthenticated do not change display state (ie, continue acting as if it is false or undefined)
  5. if I console.log this.get('session.isAuthenticated') I get true

When this was just torii everything was working, so I've messed up when adding ember-simple-auth somehow.

I get several "DEPRECATION: Using the injected 'container' is deprecated. Please use the 'getOwner' helper instead to access the owner of this object warnings but when it was just torii it worked fine with these warning so I assume they still aren't a problem.

templates/application.hbs

<header>
  <nav class="nav-main">
    {{#if session.isAuthenticated}}
      <button {{action 'invalidateSession'}}>Sign out</button>
    {{else}}
      <button {{action 'authenticate'}}>Sign in</button>
    {{/if}}

    Auth: {{session.isAuthenticated}}<br>
    <button {{action 'icanhaz'}}>test?</button>
  </nav>
</header>

routes/application.js

import Ember from 'ember';
import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin';

export default Ember.Route.extend(ApplicationRouteMixin, {
  session: Ember.inject.service('session'),
  actions: {
    authenticate() {
      this.get('session').authenticate('authenticator:torii', 'myprovider');
    },
    invalidateSession() {
      this.get('session').invalidate();
    },
    icanhaz() {
      console.log(this.get('session.isAuthenticated'));
    }
  }
});

adapters/application.js

import DS from 'ember-data';

export default DS.JSONAPIAdapter.extend({
  host: 'http://ift.tt/1ovX52H',
  namespace: 'api/v2'
});

authenticators/torii.js

import Ember from 'ember';
import ToriiAuthenticator from 'ember-simple-auth/authenticators/torii';

export default ToriiAuthenticator.extend({
  torii: Ember.inject.service(),
})

environment.js

module.exports = function(environment) {
  var ENV = {
    modulePrefix: 'my-app-prefix',
    environment: environment,
    baseURL: '/',
    locationType: 'auto',
    },
    contentSecurityPolicy: {
        'connect-src': "'self' myprovider.herokuapp.com",
    },
    torii: {
      providers: {
        'myprovider': {
          apiKey: '6T7hlTUqfYMgcxkXPAOeNzVmC5L26bTYe9A8D5fc',
          scope: 'read write',
          redirectUri: 'http://localhost:4200'
        }
      }
    }
  };
};




Aucun commentaire:

Enregistrer un commentaire