From 6cb04e4c4158c96b27b0c9bcce121088b2c2422b Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Mon, 4 Sep 2017 20:17:04 +0100 Subject: [PATCH] Removed defunct Ghost OAuth code (#848) refs https://github.com/TryGhost/Ghost/issues/8958 - Ghost OAuth isn't coming back, time for the code to disappear and simply all the things - fixes the `Usage of router is deprecated` notices that flood the console/test logs when testing --- app/authenticators/oauth2-ghost.js | 40 ---- app/components/modals/re-authenticate.js | 33 +-- app/controllers/setup/two.js | 62 +---- app/controllers/signin.js | 19 -- app/controllers/signup.js | 23 -- app/controllers/team/user.js | 18 +- app/routes/setup.js | 7 +- app/services/config.js | 5 - .../components/modals/re-authenticate.hbs | 20 +- app/templates/setup/two.hbs | 217 +++++++----------- app/templates/signin.hbs | 101 ++++---- app/templates/signup.hbs | 135 +++++------ app/templates/team/user.hbs | 7 - app/torii-providers/ghost-oauth2.js | 44 ---- app/validators/new-user.js | 11 +- app/validators/setup.js | 13 +- config/environment.js | 4 +- mirage/config/authentication.js | 33 +-- mirage/fixtures/configurations.js | 3 - package.json | 1 - tests/acceptance/setup-test.js | 104 --------- tests/acceptance/signin-test.js | 43 ---- tests/acceptance/signup-test.js | 56 ----- tests/acceptance/team-test.js | 29 --- tests/helpers/configuration.js | 12 - tests/helpers/oauth.js | 39 ---- yarn.lock | 11 +- 27 files changed, 208 insertions(+), 882 deletions(-) delete mode 100644 app/authenticators/oauth2-ghost.js delete mode 100644 app/torii-providers/ghost-oauth2.js delete mode 100644 tests/helpers/configuration.js delete mode 100644 tests/helpers/oauth.js diff --git a/app/authenticators/oauth2-ghost.js b/app/authenticators/oauth2-ghost.js deleted file mode 100644 index 1a57b2134..000000000 --- a/app/authenticators/oauth2-ghost.js +++ /dev/null @@ -1,40 +0,0 @@ -import Oauth2Authenticator from './oauth2'; -import RSVP from 'rsvp'; -import {assign} from '@ember/polyfills'; -import {isEmpty} from '@ember/utils'; -import {run} from '@ember/runloop'; -import {makeArray as wrap} from '@ember/array'; - -export default Oauth2Authenticator.extend({ - // TODO: all this is doing is changing the `data` structure, we should - // probably create our own token auth, maybe look at - // https://github.com/jpadilla/ember-simple-auth-token - authenticate(identification, password, scope = []) { - return new RSVP.Promise((resolve, reject) => { - // const data = { 'grant_type': 'password', username: identification, password }; - let data = identification; - let serverTokenEndpoint = this.get('serverTokenEndpoint'); - let scopesString = wrap(scope).join(' '); - - // eslint-disable-next-line camelcase - data.grant_type = 'authorization_code'; - - if (!isEmpty(scopesString)) { - data.scope = scopesString; - } - - this.makeRequest(serverTokenEndpoint, data).then((response) => { - run(() => { - let expiresAt = this._absolutizeExpirationTime(response.expires_in); - this._scheduleAccessTokenRefresh(response.expires_in, expiresAt, response.refresh_token); - if (!isEmpty(expiresAt)) { - response = assign(response, {'expires_at': expiresAt}); - } - resolve(response); - }); - }, (error) => { - reject(error); - }); - }); - } -}); diff --git a/app/components/modals/re-authenticate.js b/app/components/modals/re-authenticate.js index ececa1b3f..a7fca0f28 100644 --- a/app/components/modals/re-authenticate.js +++ b/app/components/modals/re-authenticate.js @@ -15,7 +15,6 @@ export default ModalComponent.extend(ValidationEngine, { config: injectService(), notifications: injectService(), session: injectService(), - torii: injectService(), identification: computed('session.user.email', function () { return this.get('session.user.email'); @@ -69,38 +68,8 @@ export default ModalComponent.extend(ValidationEngine, { }); }, - _oauthConfirm() { - // TODO: remove duplication between signin/signup/re-auth - let authStrategy = 'authenticator:oauth2-ghost'; - - this.toggleProperty('submitting'); - this.set('authenticationError', ''); - - return this.get('torii') - .open('ghost-oauth2', {type: 'signin'}) - .then((authentication) => { - this.get('session').set('skipAuthSuccessHandler', true); - - this.get('session').authenticate(authStrategy, authentication).finally(() => { - this.get('session').set('skipAuthSuccessHandler', undefined); - - this.toggleProperty('submitting'); - this.get('notifications').closeAlerts(); - this.send('closeModal'); - }); - }) - .catch(() => { - this.toggleProperty('submitting'); - this.set('authenticationError', 'Authentication with Ghost.org denied or failed'); - }); - }, - reauthenticate: task(function* () { - if (this.get('config.ghostOAuth')) { - return yield this._oauthConfirm(); - } else { - return yield this._passwordConfirm(); - } + return yield this._passwordConfirm(); }).drop(), actions: { diff --git a/app/controllers/setup/two.js b/app/controllers/setup/two.js index 923f7df19..3b99e86a0 100644 --- a/app/controllers/setup/two.js +++ b/app/controllers/setup/two.js @@ -16,7 +16,6 @@ export default Controller.extend(ValidationEngine, { notifications: injectService(), session: injectService(), settings: injectService(), - torii: injectService(), // ValidationEngine settings validationType: 'setup', @@ -30,33 +29,9 @@ export default Controller.extend(ValidationEngine, { password: null, setup: task(function* () { - if (this.get('config.ghostOAuth')) { - return yield this._oauthSetup(); - } else { - return yield this._passwordSetup(); - } + return yield this._passwordSetup(); }), - // TODO: remove duplication with controllers/signin - authenticateWithGhostOrg: task(function* () { - let authStrategy = 'authenticator:oauth2-ghost'; - - this.set('flowErrors', ''); - - try { - let authentication = yield this.get('torii') - .open('ghost-oauth2', {type: 'setup'}); - - yield this.get('authenticate').perform(authStrategy, [authentication]); - - return true; - - } catch (error) { - this.set('flowErrors', 'Authentication with Ghost.org denied or failed'); - throw error; - } - }).drop(), - authenticate: task(function* (authStrategy, authentication) { // we don't want to redirect after sign-in during setup this.set('session.skipAuthSuccessHandler', true); @@ -166,41 +141,6 @@ export default Controller.extend(ValidationEngine, { }); }, - // NOTE: for OAuth ghost is in the "setup completed" step as soon - // as a user has been authenticated so we need to use the standard settings - // update to set the blog title before redirecting - _oauthSetup() { - let blogTitle = this.get('blogTitle'); - let config = this.get('config'); - - this.get('hasValidated').addObjects(['blogTitle', 'session']); - - return this.validate().then(() => { - return this.get('settings').fetch() - .then((settings) => { - settings.set('title', blogTitle); - - return settings.save() - .then((settings) => { - // update the config so that the blog title shown in - // the nav bar is also updated - config.set('blogTitle', settings.get('title')); - - // this.blogCreated is used by step 3 to check if step 2 - // has been completed - this.set('blogCreated', true); - return this._afterAuthentication(settings); - }) - .catch((error) => { - this._handleSaveError(error); - }); - }) - .finally(() => { - this.set('session.skipAuthSuccessHandler', undefined); - }); - }); - }, - _handleSaveError(resp) { if (isInvalidError(resp)) { this.set('flowErrors', resp.errors[0].message); diff --git a/app/controllers/signin.js b/app/controllers/signin.js index 4386848a3..c19640e09 100644 --- a/app/controllers/signin.js +++ b/app/controllers/signin.js @@ -20,7 +20,6 @@ export default Controller.extend(ValidationEngine, { notifications: injectService(), session: injectService(), settings: injectService(), - torii: injectService(), flowErrors: '', @@ -92,24 +91,6 @@ export default Controller.extend(ValidationEngine, { } }).drop(), - // TODO: remove duplication with controllers/setup/two - authenticateWithGhostOrg: task(function* () { - let authStrategy = 'authenticator:oauth2-ghost'; - - this.set('flowErrors', ''); - - try { - let authentication = yield this.get('torii') - .open('ghost-oauth2', {type: 'signin'}); - - return yield this.get('authenticate').perform(authStrategy, [authentication]); - - } catch (error) { - this.set('flowErrors', 'Authentication with Ghost.org denied or failed'); - throw error; - } - }).drop(), - forgotten: task(function* () { let email = this.get('model.identification'); let forgottenUrl = this.get('ghostPaths.url').api('authentication', 'passwordreset'); diff --git a/app/controllers/signup.js b/app/controllers/signup.js index a50d5c155..510a3d7f5 100644 --- a/app/controllers/signup.js +++ b/app/controllers/signup.js @@ -5,7 +5,6 @@ import { VersionMismatchError, isVersionMismatchError } from 'ghost-admin/services/ajax'; -import {assign} from '@ember/polyfills'; import {inject as injectService} from '@ember/service'; import {isArray as isEmberArray} from '@ember/array'; import {task} from 'ember-concurrency'; @@ -17,7 +16,6 @@ export default Controller.extend(ValidationEngine, { notifications: injectService(), session: injectService(), settings: injectService(), - torii: injectService(), // ValidationEngine settings validationType: 'signup', @@ -70,27 +68,6 @@ export default Controller.extend(ValidationEngine, { } }).drop(), - authenticateWithGhostOrg: task(function* () { - let authStrategy = 'authenticator:oauth2-ghost'; - let inviteToken = this.get('model.token'); - let email = this.get('model.email'); - - this.set('flowErrors', ''); - - try { - let authentication = yield this.get('torii') - .open('ghost-oauth2', {email, type: 'invite'}); - - authentication = assign(authentication, {inviteToken}); - - return yield this.get('authenticate').perform(authStrategy, [authentication]); - - } catch (error) { - this.set('flowErrors', 'Authentication with Ghost.org denied or failed'); - throw error; - } - }).drop(), - signup: task(function* () { let setupProperties = ['name', 'email', 'password', 'token']; let notifications = this.get('notifications'); diff --git a/app/controllers/team/user.js b/app/controllers/team/user.js index 0d198002a..124480a04 100644 --- a/app/controllers/team/user.js +++ b/app/controllers/team/user.js @@ -36,10 +36,12 @@ export default Controller.extend({ email: readOnly('model.email'), slugValue: boundOneWay('model.slug'), - isNotOwnersProfile: not('user.isOwner'), - isAdminUserOnOwnerProfile: and('currentUser.isAdmin', 'user.isOwner'), canAssignRoles: or('currentUser.isAdmin', 'currentUser.isOwner'), + canChangeEmail: not('isAdminUserOnOwnerProfile'), + canChangePassword: not('isAdminUserOnOwnerProfile'), canMakeOwner: and('currentUser.isOwner', 'isNotOwnProfile', 'user.isAdmin'), + isAdminUserOnOwnerProfile: and('currentUser.isAdmin', 'user.isOwner'), + isNotOwnersProfile: not('user.isOwner'), rolesDropdownIsVisible: and('isNotOwnProfile', 'canAssignRoles', 'isNotOwnersProfile'), userActionsAreVisible: or('deleteUserActionIsVisible', 'canMakeOwner'), @@ -47,14 +49,6 @@ export default Controller.extend({ return this.get('user.id') === this.get('currentUser.id'); }), isNotOwnProfile: not('isOwnProfile'), - showMyGhostLink: and('config.ghostOAuth', 'isOwnProfile'), - - canChangeEmail: computed('config.ghostOAuth', 'isAdminUserOnOwnerProfile', function () { - let ghostOAuth = this.get('config.ghostOAuth'); - let isAdminUserOnOwnerProfile = this.get('isAdminUserOnOwnerProfile'); - - return !ghostOAuth && !isAdminUserOnOwnerProfile; - }), deleteUserActionIsVisible: computed('currentUser', 'canAssignRoles', 'user', function () { if ((this.get('canAssignRoles') && this.get('isNotOwnProfile') && !this.get('user.isOwner')) @@ -64,10 +58,6 @@ export default Controller.extend({ } }), - canChangePassword: computed('config.ghostOAuth', 'isAdminUserOnOwnerProfile', function () { - return !this.get('config.ghostOAuth') && !this.get('isAdminUserOnOwnerProfile'); - }), - // duplicated in gh-user-active -- find a better home and consolidate? userDefault: computed('ghostPaths', function () { return `${this.get('ghostPaths.assetRoot')}/img/user-image.png`; diff --git a/app/routes/setup.js b/app/routes/setup.js index 46cb2ecc3..d7376c3c1 100644 --- a/app/routes/setup.js +++ b/app/routes/setup.js @@ -17,11 +17,8 @@ export default Route.extend(styleBody, { beforeModel() { this._super(...arguments); - // with OAuth auth users are authenticated on step 2 so we - // can't use the session.isAuthenticated shortcut - if (!this.get('config.ghostOAuth') && this.get('session.isAuthenticated')) { - this.transitionTo('posts'); - return; + if (this.get('session.isAuthenticated')) { + return this.transitionTo('posts'); } let authUrl = this.get('ghostPaths.url').api('authentication', 'setup'); diff --git a/app/services/config.js b/app/services/config.js index c1bd421d9..f55d11b45 100644 --- a/app/services/config.js +++ b/app/services/config.js @@ -3,7 +3,6 @@ import Service from '@ember/service'; import {assign} from '@ember/polyfills'; import {computed} from '@ember/object'; import {inject as injectService} from '@ember/service'; -import {isBlank} from '@ember/utils'; // ember-cli-shims doesn't export _ProxyMixin const {_ProxyMixin} = Ember; @@ -46,10 +45,6 @@ export default Service.extend(_ProxyMixin, { }); }), - ghostOAuth: computed('ghostAuthId', function () { - return !isBlank(this.get('ghostAuthId')); - }), - blogDomain: computed('blogUrl', function () { let blogUrl = this.get('blogUrl'); let blogDomain = blogUrl diff --git a/app/templates/components/modals/re-authenticate.hbs b/app/templates/components/modals/re-authenticate.hbs index 345a1840b..dd896700d 100644 --- a/app/templates/components/modals/re-authenticate.hbs +++ b/app/templates/components/modals/re-authenticate.hbs @@ -5,18 +5,14 @@