Skip to content
This repository was archived by the owner on Nov 28, 2022. It is now read-only.

Commit 98f24da

Browse files
kevinansfieldkirrg001
authored andcommitted
remove custom token endpoint when using Ghost OAuth (#335)
issue TryGhost/Ghost#7562 - removes the custom endpoint so that we always use `/authentication/token` - adds missing `grant_type` attribute to our auth data so that the server can switch appropriately
1 parent 928d9d4 commit 98f24da

File tree

2 files changed

+29
-27
lines changed

2 files changed

+29
-27
lines changed

app/authenticators/oauth2-ghost.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
22
import Oauth2Authenticator from './oauth2';
3-
import computed from 'ember-computed';
43
import RSVP from 'rsvp';
54
import run from 'ember-runloop';
65
import {assign} from 'ember-platform';
76
import {isEmpty} from 'ember-utils';
87
import {wrap} from 'ember-array/utils';
98

109
export default Oauth2Authenticator.extend({
11-
serverTokenEndpoint: computed('ghostPaths.apiRoot', function () {
12-
return `${this.get('ghostPaths.apiRoot')}/authentication/ghost`;
13-
}),
14-
1510
// TODO: all this is doing is changing the `data` structure, we should
1611
// probably create our own token auth, maybe look at
1712
// https://github.com/jpadilla/ember-simple-auth-token
@@ -21,9 +16,13 @@ export default Oauth2Authenticator.extend({
2116
let data = identification;
2217
let serverTokenEndpoint = this.get('serverTokenEndpoint');
2318
let scopesString = wrap(scope).join(' ');
19+
20+
data.grant_type = 'authorization_code';
21+
2422
if (!isEmpty(scopesString)) {
2523
data.scope = scopesString;
2624
}
25+
2726
this.makeRequest(serverTokenEndpoint, data).then((response) => {
2827
run(() => {
2928
let expiresAt = this._absolutizeExpirationTime(response.expires_in);

app/mirage/config/authentication.js

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,33 @@
11
/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
22
import Mirage from 'ember-cli-mirage';
33
import {isBlank} from 'ember-utils';
4+
import $ from 'jquery';
45

56
export default function mockAuthentication(server) {
6-
server.post('/authentication/token', function () {
7-
return {
8-
access_token: '5JhTdKI7PpoZv4ROsFoERc6wCHALKFH5jxozwOOAErmUzWrFNARuH1q01TYTKeZkPW7FmV5MJ2fU00pg9sm4jtH3Z1LjCf8D6nNqLYCfFb2YEKyuvG7zHj4jZqSYVodN2YTCkcHv6k8oJ54QXzNTLIDMlCevkOebm5OjxGiJpafMxncm043q9u1QhdU9eee3zouGRMVVp8zkKVoo5zlGMi3zvS2XDpx7xsfk8hKHpUgd7EDDQxmMueifWv7hv6n',
9-
expires_in: 3600,
10-
refresh_token: 'XP13eDjwV5mxOcrq1jkIY9idhdvN3R1Br5vxYpYIub2P5Hdc8pdWMOGmwFyoUshiEB62JWHTl8H1kACJR18Z8aMXbnk5orG28br2kmVgtVZKqOSoiiWrQoeKTqrRV0t7ua8uY5HdDUaKpnYKyOdpagsSPn3WEj8op4vHctGL3svOWOjZhq6F2XeVPMR7YsbiwBE8fjT3VhTB3KRlBtWZd1rE0Qo2EtSplWyjGKv1liAEiL0ndQoLeeSOCH4rTP7',
11-
token_type: 'Bearer'
12-
};
7+
server.post('/authentication/token', function (db, request) {
8+
let params = $.deparam(request.requestBody);
9+
10+
if (params.grant_type === 'authorization_code') {
11+
// OAuth sign-in
12+
if (!db.users.length) {
13+
let [role] = db.roles.where({name: 'Owner'});
14+
server.create('user', {email: 'oauthtest@example.com', roles: [role]});
15+
}
16+
17+
return {
18+
access_token: '5JhTdKI7PpoZv4ROsFoERc6wCHALKFH5jxozwOOAErmUzWrFNARuH1q01TYTKeZkPW7FmV5MJ2fU00pg9sm4jtH3Z1LjCf8D6nNqLYCfFb2YEKyuvG7zHj4jZqSYVodN2YTCkcHv6k8oJ54QXzNTLIDMlCevkOebm5OjxGiJpafMxncm043q9u1QhdU9eee3zouGRMVVp8zkKVoo5zlGMi3zvS2XDpx7xsfk8hKHpUgd7EDDQxmMueifWv7hv6n',
19+
expires_in: 3600,
20+
refresh_token: 'XP13eDjwV5mxOcrq1jkIY9idhdvN3R1Br5vxYpYIub2P5Hdc8pdWMOGmwFyoUshiEB62JWHTl8H1kACJR18Z8aMXbnk5orG28br2kmVgtVZKqOSoiiWrQoeKTqrRV0t7ua8uY5HdDUaKpnYKyOdpagsSPn3WEj8op4vHctGL3svOWOjZhq6F2XeVPMR7YsbiwBE8fjT3VhTB3KRlBtWZd1rE0Qo2EtSplWyjGKv1liAEiL0ndQoLeeSOCH4rTP7'
21+
};
22+
} else {
23+
// Password sign-in
24+
return {
25+
access_token: '5JhTdKI7PpoZv4ROsFoERc6wCHALKFH5jxozwOOAErmUzWrFNARuH1q01TYTKeZkPW7FmV5MJ2fU00pg9sm4jtH3Z1LjCf8D6nNqLYCfFb2YEKyuvG7zHj4jZqSYVodN2YTCkcHv6k8oJ54QXzNTLIDMlCevkOebm5OjxGiJpafMxncm043q9u1QhdU9eee3zouGRMVVp8zkKVoo5zlGMi3zvS2XDpx7xsfk8hKHpUgd7EDDQxmMueifWv7hv6n',
26+
expires_in: 3600,
27+
refresh_token: 'XP13eDjwV5mxOcrq1jkIY9idhdvN3R1Br5vxYpYIub2P5Hdc8pdWMOGmwFyoUshiEB62JWHTl8H1kACJR18Z8aMXbnk5orG28br2kmVgtVZKqOSoiiWrQoeKTqrRV0t7ua8uY5HdDUaKpnYKyOdpagsSPn3WEj8op4vHctGL3svOWOjZhq6F2XeVPMR7YsbiwBE8fjT3VhTB3KRlBtWZd1rE0Qo2EtSplWyjGKv1liAEiL0ndQoLeeSOCH4rTP7',
28+
token_type: 'Bearer'
29+
};
30+
}
1331
});
1432

1533
server.post('/authentication/passwordreset', function (db, request) {
@@ -85,19 +103,4 @@ export default function mockAuthentication(server) {
85103
]
86104
};
87105
});
88-
89-
/* OAuth ---------------------------------------------------------------- */
90-
91-
server.post('/authentication/ghost', function (db) {
92-
if (!db.users.length) {
93-
let [role] = db.roles.where({name: 'Owner'});
94-
server.create('user', {email: 'oauthtest@example.com', roles: [role]});
95-
}
96-
97-
return {
98-
access_token: '5JhTdKI7PpoZv4ROsFoERc6wCHALKFH5jxozwOOAErmUzWrFNARuH1q01TYTKeZkPW7FmV5MJ2fU00pg9sm4jtH3Z1LjCf8D6nNqLYCfFb2YEKyuvG7zHj4jZqSYVodN2YTCkcHv6k8oJ54QXzNTLIDMlCevkOebm5OjxGiJpafMxncm043q9u1QhdU9eee3zouGRMVVp8zkKVoo5zlGMi3zvS2XDpx7xsfk8hKHpUgd7EDDQxmMueifWv7hv6n',
99-
expires_in: 3600,
100-
refresh_token: 'XP13eDjwV5mxOcrq1jkIY9idhdvN3R1Br5vxYpYIub2P5Hdc8pdWMOGmwFyoUshiEB62JWHTl8H1kACJR18Z8aMXbnk5orG28br2kmVgtVZKqOSoiiWrQoeKTqrRV0t7ua8uY5HdDUaKpnYKyOdpagsSPn3WEj8op4vHctGL3svOWOjZhq6F2XeVPMR7YsbiwBE8fjT3VhTB3KRlBtWZd1rE0Qo2EtSplWyjGKv1liAEiL0ndQoLeeSOCH4rTP7'
101-
};
102-
});
103106
}

0 commit comments

Comments
 (0)