How to use the ember-simple-auth/authenticators/base.extend function in ember-simple-auth

To help you get started, we’ve selected a few ember-simple-auth examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github coding-blocks / hacker-blocks / app / authenticators / custom.js View on Github external
/**
 * Created by umair on 03/01/17.
 */

import Ember from 'ember';
import jwtDecode from 'ember-cli-jwt-decode';
import Base from 'ember-simple-auth/authenticators/base';
import { task, timeout } from 'ember-concurrency';
import env from '../config/environment';

export default Base.extend({
  refreshToken: null,
  jwt: null,
  restore(data) {
    return new Ember.RSVP.Promise( (resolve, reject) => {
      if (!Ember.isNone(data.jwt) && !Ember.isNone(data.refresh_token)) {

        // Make an immediate request
        //debugger;
        this.refreshToken = data.refresh_token
        this._scheduleRefreshTokenRequest(data.jwt)
        resolve(data);
      } else {
        console.log("Old logging system detected. Logging out.");
        reject();
      }
    });
github NREL / api-umbrella / src / api-umbrella / admin-ui / app / authenticators / devise-server-side.js View on Github external
import $ from 'jquery';
import Base from 'ember-simple-auth/authenticators/base';
import { Promise } from 'rsvp';
import bootbox from 'bootbox';
import { run } from '@ember/runloop';

export default Base.extend({
  restore() {
    // Perform a full validation against the server-side endpoint to verify the
    // user's authentication on load. We use this, instead of validating the
    // data stored client side, since the user's server-side session may have
    // expired, even if the local client data thinks it's authenticated.
    return this.authenticate();
  },

  authenticate() {
    return new Promise((resolve, reject) => {
      $.ajax({
        url: '/admin/auth',
      }).done((data) => {
        if(this._validate(data)) {
          run(null, resolve, data);
        } else {
github mozilla / fxa / packages / fxa-oauth-console / app / authenticators / custom.js View on Github external
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import Ember from 'ember';
import Base from 'ember-simple-auth/authenticators/base';
import config from '../config/environment';

/**
 * Custom Ember Simple Auth Authenticator
 * See docs: http://ember-simple-auth.simplabs.com/ember-simple-auth-api-docs.html
 */
export default Base.extend({
  /**
   * Token endpoint
   */
  tokenEndpoint: config.baseURL + 'oauth',
  /**
   * Restores application session data
   *
   * @param data
   * @returns {Rx.Promise}
   */
  restore: function(data) {
    return new Ember.RSVP.Promise(function(resolve, reject) {
      if (!Ember.isEmpty(data.token)) {
        resolve(data);
      } else {
        reject();
github jpadilla / ember-simple-auth-token / addon / authenticators / token.js View on Github external
import { Promise, reject, resolve } from 'rsvp';
import { isEmpty } from '@ember/utils';
import Base from 'ember-simple-auth/authenticators/base';
import config from 'ember-get-config';

/**
  Authenticator that works with token-based authentication like JWT.

  _The factory for this authenticator is registered as `'authenticator:token'` in Ember's container._

  @class Token
  @namespace SimpleAuth.Authenticators
  @module ember-simple-auth-token/authenticators/token
  @extends Base
*/
export default Base.extend({
  /**
    @method init
  */
  init() {
    this._super(...arguments);
    const conf = config['ember-simple-auth-token'] || {};
    this.serverTokenEndpoint = conf.serverTokenEndpoint || '/api/token-auth/';
    this.tokenPropertyName = conf.tokenPropertyName || 'token';
    this.headers = conf.headers || {};
  },

  /**
    Restores the session from a set of session properties; __will return a resolving promise when there's a non-empty `token` in the `properties`__ and a rejecting promise otherwise.

    @method restore
    @param {Object} properties The properties to restore the session from
github jamesdixon / ember-cli-simple-auth-firebase / app / authenticators / firebase.js View on Github external
import Base from 'ember-simple-auth/authenticators/base';
import Firebase from 'firebase';
import config from '../config/environment';

const { Promise } = Ember.RSVP;

export default Base.extend({

    init: function() {
        if (config.firebase) {
            this.set('firebase', new Firebase(config.firebase));
        } else {
            throw new Error("'firebase' not defined in environment");
        }

        this._super();
    },
    firebase: null,
    restore: function(data) {

        var _this = this;

        return new Promise(function(resolve, reject) {
github mapeveri / muss / static / muss / app / authenticators / jwt.js View on Github external
import { run } from '@ember/runloop';
import { isEmpty } from '@ember/utils';
import { Promise } from 'rsvp';
import Base from 'ember-simple-auth/authenticators/base';
import $ from 'jquery';
import ENV from '../config/environment';

export default Base.extend({
    tokenEndpoint: ENV.APP.API_HOST + '/' + ENV.APP.API_NAMESPACE + '/token-auth/',
    verifyTokenEndpoint: ENV.APP.API_HOST + '/' + ENV.APP.API_NAMESPACE + '/api-token-verify/',
    restore(data) {
        return new Promise((resolve, reject) => {
            if (!isEmpty(data.token)) {
                const requestOptions = {
                    url: this.verifyTokenEndpoint,
                    type: 'POST',
                    contentType: "application/x-www-form-urlencoded",
                    data: {
                        token: data.token,
                    },
                    headers: {
                        'Authorization': "jwt " + data.token
                    }
                };
github HospitalRun / hospitalrun-frontend / app / authenticators / custom.js View on Github external
import { inject as service } from '@ember/service';
import { alias } from '@ember/object/computed';
import { get } from '@ember/object';
import RSVP from 'rsvp';
import BaseAuthenticator from 'ember-simple-auth/authenticators/base';
import crypto from 'npm:crypto';
import MapOauthParams from 'hospitalrun/mixins/map-oauth-params';
import OAuthHeaders from 'hospitalrun/mixins/oauth-headers';

export default BaseAuthenticator.extend(MapOauthParams, OAuthHeaders, {
  ajax: service(),
  config: service(),
  database: service(),
  serverEndpoint: '/auth/login',

  standAlone: alias('config.standAlone'),
  usersDB: alias('database.usersDB'),

  _checkUser(user, oauthConfigs) {
    return new RSVP.Promise((resolve, reject) => {
      let headers = this.getOAuthHeaders(oauthConfigs);
      this._makeRequest({ name: user.name }, '/chkuser', headers).then((response) => {
        if (response.error) {
          reject(response);
        }
        user.displayName = response.displayName;
github cardstack / cardstack / packages / authentication / addon / cardstack-authenticator.js View on Github external
import { warn } from '@ember/debug';
import { inject as service } from '@ember/service';
import { get } from '@ember/object';
import Base from 'ember-simple-auth/authenticators/base';
import RSVP from 'rsvp';
import { hubURL } from '@cardstack/plugin-utils/environment';

const clientId = Math.floor(Math.random() * 10000000000);
const validTokenGracePeriod = 10 * 1000;

export default Base.extend({
  cardstackSession: service(),
  session: service(),

  async restore(rawSession) {
    return new RSVP.Promise((resolve, reject) => {
      let potentiallyValidSession =
        rawSession &&
        rawSession.data &&
        rawSession.data.meta &&
        rawSession.data.meta.validUntil &&
        rawSession.data.meta.validUntil > Date.now() / 1000;

      let { token: prevToken, clientId: tokenClientId, issued: tokenIssued } = JSON.parse(
        localStorage.getItem('cardstack-prev-token') || '{}'
      );
      if (
github plantinformatics / pretzel / frontend / app / authenticators / pretzel-local.js View on Github external
import Ember from 'ember';
import Base from 'ember-simple-auth/authenticators/base';

export default Base.extend({
  restore: function(data) {
    return new Ember.RSVP.Promise(function(resolve, reject){
      if(!Ember.isEmpty(data.token)) {
        resolve(data);
      } else {
        reject();
      }
    });
  },

  authenticate: function(identification, password) {
    let config = Ember.getOwner(this).resolveRegistration('config:environment')
    let endpoint = config.apiHost + '/api/Clients/login'
    return new Ember.RSVP.Promise((resolve, reject) => {
      Ember.$.ajax({
        url: endpoint,