import SessionService from 'ember-simple-auth/services/session';

The session service provides access to the current session as well as methods to authenticate it, invalidate it, etc. It is the main interface for the application to Ember Simple Auth's functionality. It can be injected via

// app/components/login-form.js
          import Ember from 'ember';
          
          export default Ember.Component.extend({
            session: Ember.inject.service('session')
          });
          

Methods

source public

authenticate(authenticator, [args]) Ember.RSVP.Promise

Authenticates the session with an authenticator and appropriate arguments. The authenticator implements the actual steps necessary to authenticate the session (see authenticate) and returns a promise after doing so. The session handles the returned promise and when it resolves becomes authenticated, otherwise remains unauthenticated. All data the authenticator resolves with will be accessible via the session data's authenticated property.

This method returns a promise. A resolving promise indicates that the session was successfully authenticated while a rejecting promise indicates that authentication failed and the session remains unauthenticated. The promise does not resolve with a value; instead, the data returned from the authenticator is available via the data property.

When authentication succeeds this will trigger the authenticationSucceeded event.

Arguments

authenticator: String

The authenticator to use to authenticate the session

[...args]: Any

The arguments to pass to the authenticator; depending on the type of authenticator these might be a set of credentials, a Facebook OAuth Token, etc.

Returns

Ember.RSVP.Promise

A promise that resolves when the session was authenticated successfully and rejects otherwise

source public

authorize(authorizer, block)

Deprecated:Use Session/authorize:method instead

Authorizes a block of code with an authorizer (see authorize) if the session is authenticated. If the session is not currently authenticated this method does nothing.

this.get('session').authorize('authorizer:oauth2-bearer', (headerName, headerValue) => {
                            xhr.setRequestHeader(headerName, headerValue);
                          });
                          

Arguments

authorizer: String

The authorizer to authorize the block with

block: Function

The block of code to call with the authorization data generated by the authorizer

source public

invalidate(args) Ember.RSVP.Promise

Invalidates the session with the authenticator it is currently authenticated with (see authenticate). This invokes the authenticator's invalidate method and handles the returned promise accordingly.

This method returns a promise. A resolving promise indicates that the session was successfully invalidated while a rejecting promise indicates that invalidation failed and the session remains authenticated. Once the session is successfully invalidated it clears all of its authenticated data (see data).

When invalidation succeeds this will trigger the invalidationSucceeded event.

When calling the invalidate on an already unauthenticated session, the method will return a resolved Promise immediately.

Arguments

args: Array

arguments that will be passed to the authenticator

Returns

Ember.RSVP.Promise

A promise that resolves when the session was invalidated successfully and rejects otherwise

Properties

source public

attemptedTransition: Transition

Default: null

A previously attempted but intercepted transition (e.g. by the AuthenticatedRouteMixin). If an attempted transition is present, the ApplicationRouteMixin will retry it when the session becomes authenticated (see sessionAuthenticated).

source public readonly

data: Object

Default: { authenticated: {} }

The current session data as a plain object. The authenticated key holds the session data that the authenticator resolved with when the session was authenticated (see authenticate) and that will be cleared when the session is invalidated. This data cannot be written. All other session data is writable and will not be cleared when the session is invalidated.

source public readonly

isAuthenticated: Boolean

Default: false

Returns whether the session is currently authenticated.

source public readonly

store: BaseStore

Default: null

The session store.

Events

source

authenticationSucceeded

Triggered whenever the session is successfully authenticated. This happens when the session gets authenticated via authenticate but also when the session is authenticated in another tab or window of the same application and the session state gets synchronized across tabs or windows via the store (see sessionDataUpdated).

When using the ApplicationRouteMixin this event will automatically get handled (see sessionAuthenticated).

source

invalidationSucceeded

Triggered whenever the session is successfully invalidated. This happens when the session gets invalidated via invalidate but also when the session is invalidated in another tab or window of the same application and the session state gets synchronized across tabs or windows via the store (see sessionDataUpdated).

When using the ApplicationRouteMixin this event will automatically get handled (see sessionInvalidated).