Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/**
* 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();
}
});
// import OAuth2Bearer from 'ember-simple-auth/authorizers/oauth2-bearer';
// export default OAuth2Bearer.extend();
import BaseAuthorizer from 'ember-simple-auth/authorizers/base'
export default BaseAuthorizer.extend({
// serverTokenEndpoint: `${config.apiHost}/Users/login`,
// serverTokenRevocationEndpoint: `${config.apiHost}/Users/logout`
authorize(data, block) {
// console.log('authorize', data, block)
block('Authorization', data.token)
}
});
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 {
/* 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();
// eslint-disable-next-line max-len
import OAuth2PasswordGrant from 'ember-simple-auth/authenticators/oauth2-password-grant';
import ENV from '../config/environment';
const serverTokenPath = '/api/oauth/token';
const serverTokenEndpoint = ENV.apiHost
? ENV.apiHost + serverTokenPath
: serverTokenPath;
export default OAuth2PasswordGrant.extend({
serverTokenEndpoint,
});
import SessionService from 'ember-simple-auth/services/session';
import {computed} from '@ember/object';
import {inject as service} from '@ember/service';
export default SessionService.extend({
dataStore: service('store'), // SessionService.store already exists
user: computed(function () {
return this.dataStore.queryRecord('user', {id: 'me'});
}),
authenticate() {
// ensure any cached this.user value is removed and re-fetched
this.notifyPropertyChange('user');
return this._super(...arguments);
}
});
// app/session-stores/application.js
import CookieStore from 'ember-simple-auth/session-stores/cookie';
export default CookieStore.extend({
restore() {
return this._super();
}
});
import Ember from 'ember';
import ToriiAuthenticator from 'ember-simple-auth/authenticators/torii';
const { inject: { service } } = Ember;
export default ToriiAuthenticator.extend({
torii: service(),
ajax: service(),
authenticate() {
const ajax = this.get('ajax');
return this._super(...arguments).then(data => {
return ajax.request('http://localhost:8888/v1/github/token', {
type: 'POST',
dataType: 'json',
data: {
authorization_code: data.authorizationCode
}
}).then(({access_token}) => {
return ajax.request('http://localhost:8888/v1/buckets/default', {
type: 'GET',
headers: {