Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
ajaxOptions() {
var hash = this._super(...arguments);
// TODO: This mechanism is quite ugly, and will require manual ajax requests (such as the file manager) to set fields separately;
// getting requests to send cookies without triggering cross-origin rules would be strongly preferable
if (config.authorizationType === 'cookie') {
Ember.$.extend(hash, {
xhrFields: {
withCredentials: true
}
});
}
return hash;
}
});
// multiple files for upload in the first place.
if (this.get('options.preventMultipleFiles') && this.get('clickable')){
Ember.$('.dz-hidden-input').removeAttr('multiple');
}
this.set('dropzoneElement', drop);
// Set osf session header
let headers = {};
let authType = config['ember-simple-auth'].authorizer;
this.get('session').authorize(authType, (headerName, content) => {
headers[headerName] = content;
});
dropzoneOptions.headers = headers;
dropzoneOptions.withCredentials = (config.authorizationType === 'cookie');
// Attach preUpload to addedfile event
drop.on('addedfile', file => {
if (preUpload) {
preUpload(this, drop, file).then(() => drop.processFile(file));
} else {
drop.processFile(file);
}
});
// Set dropzone options
drop.options = Ember.assign(drop.options, dropzoneOptions);
// Attach dropzone event listeners: http://www.dropzonejs.com/#events
drop.events.forEach(event => {
if (typeof this.get(event) === 'function') {
// multiple files for upload in the first place.
if (this.get('options.preventMultipleFiles') && this.get('clickable')) {
$('.dz-hidden-input').removeAttr('multiple');
}
this.set('dropzoneElement', drop);
// Set osf session header
const headers = {};
this.get('session')
.authorize(authType, (headerName, content) => Object.assign(headers, { [headerName]: content }));
Object.assign(dropzoneOptions, {
headers,
withCredentials: config.authorizationType === 'cookie',
});
// Attach preUpload to addedfile event
drop.on('addedfile', async file => {
if (preUpload) {
await preUpload(this, drop, file);
}
drop.processFile(file);
});
// Set dropzone options
Object.assign(drop.options, dropzoneOptions);
// Attach dropzone event listeners: http://www.dropzonejs.com/#events
drop.events.forEach(event => {
import Mixin from '@ember/object/mixin';
import config from 'ember-get-config';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
import $ from 'jquery';
const isCookieAuth = config.authorizationType === 'cookie';
/**
* Extend the Ember-Simple-Auth adapter to provide cookie support (when necessary).
* This allows the same addon to define an adapter that works with two authentication types.
*
* This particularly applies to local development, as without it cookies are not sent from the ember app to the api
* domain
*
* @class GenericDataADapter
*/
export default Mixin.create(DataAdapterMixin, {
ajaxOptions(...args: any[]): object {
const hash: object = this._super(...args);
// TODO: This mechanism is quite ugly, and will require manual ajax requests (such as the file manager) to set
// fields separately; getting requests to send cookies without triggering cross-origin rules would be strongly
import Ember from 'ember';
import config from 'ember-get-config';
import OsfTokenLoginRoute from '../mixins/osf-token-login-route';
import OsfCookieLoginRoute from '../mixins/osf-cookie-login-route';
/**
* @module ember-osf
* @submodule mixins
*/
var AuthMixin;
let authType = config.authorizationType;
if (authType === 'token') {
AuthMixin = OsfTokenLoginRoute;
} else if (authType === 'cookie') {
AuthMixin = OsfCookieLoginRoute;
} else {
throw new Ember.Error(`Unrecognized authorization type: ${authType}`);
}
/**
* Route mixin for authentication-agnostic login: defines the application at runtime to use the authentication method
* specified in environment config. Intended to be used in tandem with OsfAgnosticAuthRoute mixin.
* Some authentication methods (eg cookies) are not available to third-party applications.
* This has limited use, since most applications will only need to support one method. It may be useful for ember apps
* that run inside the OSF, eg to use the standalone dev server, or to offer support for branded apps
* on third-party domains.
*
* @class OsfAgnosticAuthRoute
import EmberError from '@ember/error';
import config from 'ember-get-config';
import OsfTokenLoginRoute from '../mixins/osf-token-login-route';
import OsfCookieLoginRoute from '../mixins/osf-cookie-login-route';
/**
* @module ember-osf-web
* @submodule mixins
*/
const authType = config.authorizationType;
if (authType !== 'token' && authType !== 'cookie') {
throw new EmberError(`Unrecognized authorization type: ${authType}`);
}
const AuthMixin = authType === 'token' ? OsfTokenLoginRoute : OsfCookieLoginRoute;
/**
* Route mixin for authentication-agnostic login: defines the application at runtime to use the authentication method
* specified in environment config. Intended to be used in tandem with OsfAgnosticAuthRoute mixin.
* Some authentication methods (eg cookies) are not available to third-party applications.
* This has limited use, since most applications will only need to support one method. It may be useful for ember apps
* that run inside the OSF, eg to use the standalone dev server, or to offer support for branded apps
* on third-party domains.
*
* @class OsfAgnosticAuthRoute
* @extends Ember.Mixin
* @uses ember-osf-web/OsfCookieLoginRoute
function authenticatedAJAX(options) {
if (config.authorizationType === 'cookie') {
Ember.merge(options, {
xhrFields: {
withCredentials: true
}
});
}
return Ember.$.ajax(options);
}
export { authenticatedAJAX };
import Ember from 'ember';
import config from 'ember-get-config';
import OsfTokenLoginController from '../mixins/osf-token-login-controller';
import OsfCookieLoginController from '../mixins/osf-cookie-login-controller';
/**
* @module ember-osf
* @submodule mixins
*/
var AuthMixin;
let authType = config.authorizationType;
if (authType === 'token') {
AuthMixin = OsfTokenLoginController;
} else if (authType === 'cookie') {
AuthMixin = OsfCookieLoginController;
} else {
throw new Ember.Error(`Unrecognized authorization type: ${authType}`);
}
/**
* Controller mixin for authentication-agnostic login: defines the application at runtime to use the authentication method
* specified in environment config. Intended to be used in tandem with OsfAuthController mixin.
* Some authentication methods (eg cookies) are not available to third-party applications.
* This has limited use, since most applications will only need to support one method. It may be useful for ember apps
* that run inside the OSF, eg to use the standalone dev server, or to offer support for branded apps
* on third-party domains.
*
* @class OsfAgnosticAuthController
function getAuthUrl() {
let authType = config.authorizationType;
if (authType === 'token') {
return getOAuthUrl(...arguments);
} else if (authType === 'cookie') {
return getCookieAuthUrl(...arguments);
} else {
throw new Ember.Error(`Unrecognized authorization type: ${authType}`);
}
}
authenticatedAJAX(options, addApiHeaders = true) {
const opts = Ember.assign({}, options);
if (config.authorizationType === 'cookie') {
opts.xhrFields = Ember.assign({
withCredentials: true
}, opts.xhrFields || {});
}
if (addApiHeaders) {
opts.headers = Ember.assign({}, this.ajaxHeaders(), opts.headers || {});
}
return Ember.$.ajax(opts);
},