mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-26 04:08:01 +03:00
3e5a62309f
refs #9865 - removed all `oauth2` and token-based ESA auth - added new `cookie` authenticator which handles session creation - updated the session store to extend from the `ephemeral` in-memory store and to restore by fetching the currently logged in user and using the success/failure state to indicate authentication state - ESA automatically calls this `.restore()` method on app boot - the `session` service caches the current-user query so there's no unnecessary requests being made for the "logged in" state - removed the now-unnecessary token refresh and logout routines from the `application` route - removed the now-unnecessary token refresh routines from the `ajax` service - removed `access_token` query param from iframe file downloaders - changed Ember Data adapters and `ghost-paths` to use the `/ghost/api/v2/admin/` namespace
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
import Authenticator from 'ember-simple-auth/authenticators/base';
|
|
import RSVP from 'rsvp';
|
|
import {computed} from '@ember/object';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
export default Authenticator.extend({
|
|
ajax: service(),
|
|
ghostPaths: service(),
|
|
|
|
sessionEndpoint: computed('ghostPaths.apiRoot', function () {
|
|
return `${this.ghostPaths.apiRoot}/session`;
|
|
}),
|
|
|
|
restore: function () {
|
|
return RSVP.resolve();
|
|
},
|
|
|
|
authenticate(identification, password) {
|
|
const data = {username: identification, password};
|
|
const options = {
|
|
data,
|
|
contentType: 'application/json;charset=utf-8',
|
|
// ember-ajax will try and parse the response as JSON if not explicitly set
|
|
dataType: 'text'
|
|
};
|
|
|
|
return this.ajax.post(this.sessionEndpoint, options);
|
|
},
|
|
|
|
invalidate() {
|
|
// if we're invalidating because of a 401 we can end up in an infinite
|
|
// loop if we then try to perform a DELETE /session/ request
|
|
// TODO: find a more elegant way to handle this
|
|
if (this.ajax.skipSessionDeletion) {
|
|
this.ajax.skipSessionDeletion = false;
|
|
return RSVP.resolve();
|
|
}
|
|
|
|
return this.ajax.del(this.sessionEndpoint);
|
|
}
|
|
});
|