× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Ember.js Authenticate user from code with Ember Simple Auth

Marco Otte-Witte
Mar 07, 2015
<p>To authenticate the session either via a regular login (probably with EmberSimpleAuth's default authenticator) or automatically after successful signup, you'd use a different authenticator for each case. For the login you'd use the default authenticator with the LoginControllerMixin etc. and for the automatic case you'd use a custom authenticator. For docs on using custom authenticators see the examples in EmberSimpleAuth's github repo an the API docs: <a href="http://ember-simple-auth.simplabs.com/api.html">http://ember-simple-auth.simplabs.com/api.html</a>.</p> <p>Basically what you'd do is:</p> <pre><code>App.AutoAuthenticator = Ember.SimpleAuth.Authenticators.OAuth2.extend({ authenticate: function(credentials) { if (!Ember.isEmpty(credentials.access_token)) { return Ember.RSVP.resolve(credentials); } else { return this._super(credentials); } } }); Ember.Application.initializer({ name: 'authentication', initialize: function(container, application) { container.register('app:authenticators:custom', App.AutoAuthenticator); Ember.SimpleAuth.setup(container, application); } }); this.get('session').authenticate('app:auto-authenticator', { access_token: 'secret token!' }) </code></pre> <p>I did not actually test that - please regard this as pseudo code ;)</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/22376881/Ember.js%20Authenticate%20user%20from%20code%20with%20Ember%20Simple%20Auth/22464113">Stack Overflow</a>.</p>
comments powered by Disqus