2018-12-11 09:47:44 +03:00
|
|
|
const {Router, static} = require('express');
|
|
|
|
const body = require('body-parser');
|
|
|
|
|
2019-01-22 17:29:44 +03:00
|
|
|
const {getData, handleError} = require('./util');
|
|
|
|
|
|
|
|
const Cookies = require('./cookies');
|
|
|
|
const Tokens = require('./tokens');
|
|
|
|
const Users = require('./users');
|
2019-02-07 12:41:39 +03:00
|
|
|
const Subscriptions = require('./subscriptions');
|
2018-12-11 09:47:44 +03:00
|
|
|
|
|
|
|
module.exports = function MembersApi({
|
2019-02-07 12:41:39 +03:00
|
|
|
authConfig: {
|
2018-12-11 09:47:44 +03:00
|
|
|
issuer,
|
|
|
|
privateKey,
|
|
|
|
publicKey,
|
|
|
|
sessionSecret,
|
Updated theme layer to use members-ssr (#10676)
* Removed support for cookies in members auth middleware
no-issue
The members middleware will no longer be supporting cookies, the cookie
will be handled by a new middleware specific for serverside rendering,
more informations can be found here:
https://paper.dropbox.com/doc/Members-Auth-II-4WP4vF6coMqDYbSMIajo5
* Removed members auth middleware from site app
no-issue
The site app no longer needs the members auth middleware as it doesn't
support cookies, and will be replaced by ssr specific middleware.
https://paper.dropbox.com/doc/Members-Auth-II-4WP4vF6coMqDYbSMIajo5
* Added comment for session_secret setting
no-issue
We are going to have multiple concepts of sessions, so adding a comment
here to be specific that this is for the Ghost Admin client
* Added theme_session_secret setting dynamic default
no-issue
Sessions for the theme layer will be signed, so we generate a random hex
string to use as a signing key
* Added getPublicConfig method
* Replaced export of httpHandler with POJO apiInstance
no-issue
This is mainly to reduce the public api, so it's easier to document.
* Renamed memberUserObject -> members
no-issue
Simplifies the interface, and is more inline with what we would want to export as an api library.
* Removed use of require options inside members
no-issue
This was too tight of a coupling between Ghost and Members
* Simplified apiInstance definition
no-issue
* Added getMember method to members api
* Added MembersSSR instance to members service
* Wired up routes for members ssr
* Updated members auth middleware to use getPublicConfig
* Removed publicKey static export from members service
* Used real session secret
no-issue
* Added DELETE /members/ssr handler
no-issue
This allows users to log out of the theme layer
* Fixed missing code property
no-issue
Ignition uses the statusCode property to forward status codes to call sites
* Removed superfluous error middleware
no-issue
Before we used generic JWT middleware which would reject, now the
middleware catches it's own error and doesn't error, thus this
middleware is unecessary.
* Removed console.logs
no-issue
* Updated token expirty to hardcoded 20 minutes
no-issue
This returns to our previous state of using short lived tokens, both for
security and simplicity.
* Removed hardcoded default member settings
no-issue
This is no longer needed, as defaults are in default-settings.json
* Removed stripe from default payment processor
no-issue
* Exported `getSiteUrl` method from url utils
no-issue
This keeps inline with newer naming conventions
* Updated how audience access control works
no-issue
Rather than being passed a function, members api now receives an object
which describes which origins have access to which audiences, and how
long those tokens should be allowed to work for. It also allows syntax
for default tokens where audience === origin requesting it. This can be
set to undefined or null to disable this functionality.
{
"http://site.com": {
"http://site.com": {
tokenLength: '5m'
},
"http://othersite.com": {
tokenLength: '1h'
}
},
"*": {
tokenLength: '30m'
}
}
* Updated members service to use access control feature
no-issue
This also cleans up a lot of unecessary variable definitions, and some
other minor cleanups.
* Added status code to auth pages html response
no-issue
This was missing, probably default but better to be explicit
* Updated gateway to have membersApiUrl from config
no-issue
Previously we were parsing the url, this was not very safe as we can
have Ghost hosted on a subdomain, and this would have failed.
* Added issuer to public config for members
no-issue
This can be used to request SSR tokens in the client
* Fixed path for gateway bundle
no-issue
* Updated settings model tests
no-issue
* Revert "Removed stripe from default payment processor"
This reverts commit 1d88d9b6d73a10091070bcc1b7f5779d071c7845.
* Revert "Removed hardcoded default member settings"
This reverts commit 9d899048ba7d4b272b9ac65a95a52af66b30914a.
* Installed @tryghost/members-ssr
* Fixed tests for settings model
2019-04-16 17:50:25 +03:00
|
|
|
ssoOrigin,
|
|
|
|
accessControl
|
2018-12-11 09:47:44 +03:00
|
|
|
},
|
2019-02-07 12:41:39 +03:00
|
|
|
paymentConfig,
|
2018-12-11 09:47:44 +03:00
|
|
|
createMember,
|
|
|
|
validateMember,
|
|
|
|
updateMember,
|
|
|
|
getMember,
|
2019-04-13 08:08:56 +03:00
|
|
|
deleteMember,
|
2019-01-30 14:36:09 +03:00
|
|
|
listMembers,
|
2019-02-26 06:09:16 +03:00
|
|
|
sendEmail,
|
|
|
|
siteConfig
|
2018-12-11 09:47:44 +03:00
|
|
|
}) {
|
2019-01-22 17:29:44 +03:00
|
|
|
const {encodeToken, decodeToken, getPublicKeys} = Tokens({privateKey, publicKey, issuer});
|
|
|
|
|
2019-02-26 06:09:16 +03:00
|
|
|
let subscriptions = new Subscriptions(paymentConfig);
|
2019-02-07 12:41:39 +03:00
|
|
|
|
2019-02-26 06:09:16 +03:00
|
|
|
let users = Users({
|
2019-02-07 12:41:39 +03:00
|
|
|
subscriptions,
|
2019-01-22 17:29:44 +03:00
|
|
|
createMember,
|
|
|
|
updateMember,
|
|
|
|
getMember,
|
2019-04-13 08:08:56 +03:00
|
|
|
deleteMember,
|
2019-01-22 17:29:44 +03:00
|
|
|
validateMember,
|
|
|
|
sendEmail,
|
|
|
|
encodeToken,
|
2019-01-30 14:36:09 +03:00
|
|
|
listMembers,
|
2019-01-22 17:29:44 +03:00
|
|
|
decodeToken
|
|
|
|
});
|
2018-12-11 09:47:44 +03:00
|
|
|
|
|
|
|
const router = Router();
|
|
|
|
|
|
|
|
const apiRouter = Router();
|
|
|
|
|
|
|
|
apiRouter.use(body.json());
|
|
|
|
|
2019-01-22 17:29:44 +03:00
|
|
|
/* session */
|
|
|
|
const {getCookie, setCookie, removeCookie} = Cookies(sessionSecret);
|
2018-12-11 09:47:44 +03:00
|
|
|
|
Updated theme layer to use members-ssr (#10676)
* Removed support for cookies in members auth middleware
no-issue
The members middleware will no longer be supporting cookies, the cookie
will be handled by a new middleware specific for serverside rendering,
more informations can be found here:
https://paper.dropbox.com/doc/Members-Auth-II-4WP4vF6coMqDYbSMIajo5
* Removed members auth middleware from site app
no-issue
The site app no longer needs the members auth middleware as it doesn't
support cookies, and will be replaced by ssr specific middleware.
https://paper.dropbox.com/doc/Members-Auth-II-4WP4vF6coMqDYbSMIajo5
* Added comment for session_secret setting
no-issue
We are going to have multiple concepts of sessions, so adding a comment
here to be specific that this is for the Ghost Admin client
* Added theme_session_secret setting dynamic default
no-issue
Sessions for the theme layer will be signed, so we generate a random hex
string to use as a signing key
* Added getPublicConfig method
* Replaced export of httpHandler with POJO apiInstance
no-issue
This is mainly to reduce the public api, so it's easier to document.
* Renamed memberUserObject -> members
no-issue
Simplifies the interface, and is more inline with what we would want to export as an api library.
* Removed use of require options inside members
no-issue
This was too tight of a coupling between Ghost and Members
* Simplified apiInstance definition
no-issue
* Added getMember method to members api
* Added MembersSSR instance to members service
* Wired up routes for members ssr
* Updated members auth middleware to use getPublicConfig
* Removed publicKey static export from members service
* Used real session secret
no-issue
* Added DELETE /members/ssr handler
no-issue
This allows users to log out of the theme layer
* Fixed missing code property
no-issue
Ignition uses the statusCode property to forward status codes to call sites
* Removed superfluous error middleware
no-issue
Before we used generic JWT middleware which would reject, now the
middleware catches it's own error and doesn't error, thus this
middleware is unecessary.
* Removed console.logs
no-issue
* Updated token expirty to hardcoded 20 minutes
no-issue
This returns to our previous state of using short lived tokens, both for
security and simplicity.
* Removed hardcoded default member settings
no-issue
This is no longer needed, as defaults are in default-settings.json
* Removed stripe from default payment processor
no-issue
* Exported `getSiteUrl` method from url utils
no-issue
This keeps inline with newer naming conventions
* Updated how audience access control works
no-issue
Rather than being passed a function, members api now receives an object
which describes which origins have access to which audiences, and how
long those tokens should be allowed to work for. It also allows syntax
for default tokens where audience === origin requesting it. This can be
set to undefined or null to disable this functionality.
{
"http://site.com": {
"http://site.com": {
tokenLength: '5m'
},
"http://othersite.com": {
tokenLength: '1h'
}
},
"*": {
tokenLength: '30m'
}
}
* Updated members service to use access control feature
no-issue
This also cleans up a lot of unecessary variable definitions, and some
other minor cleanups.
* Added status code to auth pages html response
no-issue
This was missing, probably default but better to be explicit
* Updated gateway to have membersApiUrl from config
no-issue
Previously we were parsing the url, this was not very safe as we can
have Ghost hosted on a subdomain, and this would have failed.
* Added issuer to public config for members
no-issue
This can be used to request SSR tokens in the client
* Fixed path for gateway bundle
no-issue
* Updated settings model tests
no-issue
* Revert "Removed stripe from default payment processor"
This reverts commit 1d88d9b6d73a10091070bcc1b7f5779d071c7845.
* Revert "Removed hardcoded default member settings"
This reverts commit 9d899048ba7d4b272b9ac65a95a52af66b30914a.
* Installed @tryghost/members-ssr
* Fixed tests for settings model
2019-04-16 17:50:25 +03:00
|
|
|
function validateAccess({audience, origin}) {
|
|
|
|
const audienceLookup = accessControl[origin] || {
|
|
|
|
[origin]: accessControl['*']
|
|
|
|
};
|
|
|
|
|
|
|
|
const tokenSettings = audienceLookup[audience];
|
|
|
|
|
|
|
|
if (tokenSettings) {
|
|
|
|
return Promise.resolve(tokenSettings);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.reject();
|
|
|
|
}
|
|
|
|
|
2019-01-22 17:29:44 +03:00
|
|
|
/* token */
|
2018-12-11 09:47:44 +03:00
|
|
|
apiRouter.post('/token', getData('audience'), (req, res) => {
|
|
|
|
const {signedin} = getCookie(req);
|
|
|
|
if (!signedin) {
|
|
|
|
res.writeHead(401, {
|
|
|
|
'Set-Cookie': removeCookie()
|
|
|
|
});
|
|
|
|
return res.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
const {audience, origin} = req.data;
|
|
|
|
|
Updated theme layer to use members-ssr (#10676)
* Removed support for cookies in members auth middleware
no-issue
The members middleware will no longer be supporting cookies, the cookie
will be handled by a new middleware specific for serverside rendering,
more informations can be found here:
https://paper.dropbox.com/doc/Members-Auth-II-4WP4vF6coMqDYbSMIajo5
* Removed members auth middleware from site app
no-issue
The site app no longer needs the members auth middleware as it doesn't
support cookies, and will be replaced by ssr specific middleware.
https://paper.dropbox.com/doc/Members-Auth-II-4WP4vF6coMqDYbSMIajo5
* Added comment for session_secret setting
no-issue
We are going to have multiple concepts of sessions, so adding a comment
here to be specific that this is for the Ghost Admin client
* Added theme_session_secret setting dynamic default
no-issue
Sessions for the theme layer will be signed, so we generate a random hex
string to use as a signing key
* Added getPublicConfig method
* Replaced export of httpHandler with POJO apiInstance
no-issue
This is mainly to reduce the public api, so it's easier to document.
* Renamed memberUserObject -> members
no-issue
Simplifies the interface, and is more inline with what we would want to export as an api library.
* Removed use of require options inside members
no-issue
This was too tight of a coupling between Ghost and Members
* Simplified apiInstance definition
no-issue
* Added getMember method to members api
* Added MembersSSR instance to members service
* Wired up routes for members ssr
* Updated members auth middleware to use getPublicConfig
* Removed publicKey static export from members service
* Used real session secret
no-issue
* Added DELETE /members/ssr handler
no-issue
This allows users to log out of the theme layer
* Fixed missing code property
no-issue
Ignition uses the statusCode property to forward status codes to call sites
* Removed superfluous error middleware
no-issue
Before we used generic JWT middleware which would reject, now the
middleware catches it's own error and doesn't error, thus this
middleware is unecessary.
* Removed console.logs
no-issue
* Updated token expirty to hardcoded 20 minutes
no-issue
This returns to our previous state of using short lived tokens, both for
security and simplicity.
* Removed hardcoded default member settings
no-issue
This is no longer needed, as defaults are in default-settings.json
* Removed stripe from default payment processor
no-issue
* Exported `getSiteUrl` method from url utils
no-issue
This keeps inline with newer naming conventions
* Updated how audience access control works
no-issue
Rather than being passed a function, members api now receives an object
which describes which origins have access to which audiences, and how
long those tokens should be allowed to work for. It also allows syntax
for default tokens where audience === origin requesting it. This can be
set to undefined or null to disable this functionality.
{
"http://site.com": {
"http://site.com": {
tokenLength: '5m'
},
"http://othersite.com": {
tokenLength: '1h'
}
},
"*": {
tokenLength: '30m'
}
}
* Updated members service to use access control feature
no-issue
This also cleans up a lot of unecessary variable definitions, and some
other minor cleanups.
* Added status code to auth pages html response
no-issue
This was missing, probably default but better to be explicit
* Updated gateway to have membersApiUrl from config
no-issue
Previously we were parsing the url, this was not very safe as we can
have Ghost hosted on a subdomain, and this would have failed.
* Added issuer to public config for members
no-issue
This can be used to request SSR tokens in the client
* Fixed path for gateway bundle
no-issue
* Updated settings model tests
no-issue
* Revert "Removed stripe from default payment processor"
This reverts commit 1d88d9b6d73a10091070bcc1b7f5779d071c7845.
* Revert "Removed hardcoded default member settings"
This reverts commit 9d899048ba7d4b272b9ac65a95a52af66b30914a.
* Installed @tryghost/members-ssr
* Fixed tests for settings model
2019-04-16 17:50:25 +03:00
|
|
|
validateAccess({audience, origin})
|
|
|
|
.then(({tokenLength}) => {
|
|
|
|
return users.get({id: signedin})
|
|
|
|
.then(member => encodeToken({
|
|
|
|
sub: member.id,
|
|
|
|
plans: member.subscriptions.map(sub => sub.plan),
|
|
|
|
exp: tokenLength,
|
|
|
|
aud: audience
|
|
|
|
}));
|
2019-02-07 12:41:39 +03:00
|
|
|
})
|
2019-01-22 17:29:44 +03:00
|
|
|
.then(token => res.end(token))
|
|
|
|
.catch(handleError(403, res));
|
2018-12-11 09:47:44 +03:00
|
|
|
});
|
|
|
|
|
2019-02-13 12:12:15 +03:00
|
|
|
apiRouter.get('/config', (req, res) => {
|
|
|
|
subscriptions.getAdapters()
|
|
|
|
.then((adapters) => {
|
|
|
|
return Promise.all(adapters.map((adapter) => {
|
|
|
|
return subscriptions.getPublicConfig(adapter);
|
|
|
|
}));
|
|
|
|
})
|
Updated theme layer to use members-ssr (#10676)
* Removed support for cookies in members auth middleware
no-issue
The members middleware will no longer be supporting cookies, the cookie
will be handled by a new middleware specific for serverside rendering,
more informations can be found here:
https://paper.dropbox.com/doc/Members-Auth-II-4WP4vF6coMqDYbSMIajo5
* Removed members auth middleware from site app
no-issue
The site app no longer needs the members auth middleware as it doesn't
support cookies, and will be replaced by ssr specific middleware.
https://paper.dropbox.com/doc/Members-Auth-II-4WP4vF6coMqDYbSMIajo5
* Added comment for session_secret setting
no-issue
We are going to have multiple concepts of sessions, so adding a comment
here to be specific that this is for the Ghost Admin client
* Added theme_session_secret setting dynamic default
no-issue
Sessions for the theme layer will be signed, so we generate a random hex
string to use as a signing key
* Added getPublicConfig method
* Replaced export of httpHandler with POJO apiInstance
no-issue
This is mainly to reduce the public api, so it's easier to document.
* Renamed memberUserObject -> members
no-issue
Simplifies the interface, and is more inline with what we would want to export as an api library.
* Removed use of require options inside members
no-issue
This was too tight of a coupling between Ghost and Members
* Simplified apiInstance definition
no-issue
* Added getMember method to members api
* Added MembersSSR instance to members service
* Wired up routes for members ssr
* Updated members auth middleware to use getPublicConfig
* Removed publicKey static export from members service
* Used real session secret
no-issue
* Added DELETE /members/ssr handler
no-issue
This allows users to log out of the theme layer
* Fixed missing code property
no-issue
Ignition uses the statusCode property to forward status codes to call sites
* Removed superfluous error middleware
no-issue
Before we used generic JWT middleware which would reject, now the
middleware catches it's own error and doesn't error, thus this
middleware is unecessary.
* Removed console.logs
no-issue
* Updated token expirty to hardcoded 20 minutes
no-issue
This returns to our previous state of using short lived tokens, both for
security and simplicity.
* Removed hardcoded default member settings
no-issue
This is no longer needed, as defaults are in default-settings.json
* Removed stripe from default payment processor
no-issue
* Exported `getSiteUrl` method from url utils
no-issue
This keeps inline with newer naming conventions
* Updated how audience access control works
no-issue
Rather than being passed a function, members api now receives an object
which describes which origins have access to which audiences, and how
long those tokens should be allowed to work for. It also allows syntax
for default tokens where audience === origin requesting it. This can be
set to undefined or null to disable this functionality.
{
"http://site.com": {
"http://site.com": {
tokenLength: '5m'
},
"http://othersite.com": {
tokenLength: '1h'
}
},
"*": {
tokenLength: '30m'
}
}
* Updated members service to use access control feature
no-issue
This also cleans up a lot of unecessary variable definitions, and some
other minor cleanups.
* Added status code to auth pages html response
no-issue
This was missing, probably default but better to be explicit
* Updated gateway to have membersApiUrl from config
no-issue
Previously we were parsing the url, this was not very safe as we can
have Ghost hosted on a subdomain, and this would have failed.
* Added issuer to public config for members
no-issue
This can be used to request SSR tokens in the client
* Fixed path for gateway bundle
no-issue
* Updated settings model tests
no-issue
* Revert "Removed stripe from default payment processor"
This reverts commit 1d88d9b6d73a10091070bcc1b7f5779d071c7845.
* Revert "Removed hardcoded default member settings"
This reverts commit 9d899048ba7d4b272b9ac65a95a52af66b30914a.
* Installed @tryghost/members-ssr
* Fixed tests for settings model
2019-04-16 17:50:25 +03:00
|
|
|
.then(paymentConfig => res.json({
|
|
|
|
paymentConfig,
|
|
|
|
issuer,
|
|
|
|
siteConfig
|
2019-02-26 06:09:16 +03:00
|
|
|
}))
|
2019-02-13 12:12:15 +03:00
|
|
|
.catch(handleError(500, res));
|
|
|
|
});
|
|
|
|
|
2019-01-22 17:29:44 +03:00
|
|
|
/* security */
|
2018-12-11 09:47:44 +03:00
|
|
|
function ssoOriginCheck(req, res, next) {
|
|
|
|
if (!req.data.origin || req.data.origin !== ssoOrigin) {
|
|
|
|
res.writeHead(403);
|
|
|
|
return res.end();
|
|
|
|
}
|
|
|
|
next();
|
|
|
|
}
|
|
|
|
|
2019-02-07 12:41:39 +03:00
|
|
|
/* subscriptions */
|
2019-04-16 18:41:42 +03:00
|
|
|
apiRouter.post('/subscription', getData('adapter', 'plan', 'stripeToken', 'coupon'), ssoOriginCheck, (req, res) => {
|
2019-02-07 12:41:39 +03:00
|
|
|
const {signedin} = getCookie(req);
|
|
|
|
if (!signedin) {
|
|
|
|
res.writeHead(401, {
|
|
|
|
'Set-Cookie': removeCookie()
|
|
|
|
});
|
|
|
|
return res.end();
|
|
|
|
}
|
|
|
|
|
2019-04-16 18:41:42 +03:00
|
|
|
const {plan, adapter, stripeToken, coupon} = req.data;
|
2019-02-07 12:41:39 +03:00
|
|
|
|
|
|
|
subscriptions.getAdapters()
|
|
|
|
.then((adapters) => {
|
|
|
|
if (!adapters.includes(adapter)) {
|
|
|
|
throw new Error('Invalid adapter');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(() => users.get({id: signedin}))
|
|
|
|
.then((member) => {
|
|
|
|
return subscriptions.createSubscription(member, {
|
|
|
|
adapter,
|
|
|
|
plan,
|
2019-04-16 18:41:42 +03:00
|
|
|
stripeToken,
|
|
|
|
coupon
|
2019-02-07 12:41:39 +03:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
res.end();
|
|
|
|
})
|
|
|
|
.catch(handleError(500, res));
|
|
|
|
});
|
|
|
|
|
2019-01-22 17:29:44 +03:00
|
|
|
/* users, token, emails */
|
2018-12-11 09:47:44 +03:00
|
|
|
apiRouter.post('/request-password-reset', getData('email'), ssoOriginCheck, (req, res) => {
|
|
|
|
const {email} = req.data;
|
|
|
|
|
2019-01-22 17:29:44 +03:00
|
|
|
users.requestPasswordReset({email}).then(() => {
|
2018-12-11 09:47:44 +03:00
|
|
|
res.writeHead(200);
|
|
|
|
res.end();
|
|
|
|
}).catch(handleError(500, res));
|
|
|
|
});
|
|
|
|
|
2019-01-22 17:29:44 +03:00
|
|
|
/* users, token */
|
2018-12-11 09:47:44 +03:00
|
|
|
apiRouter.post('/reset-password', getData('token', 'password'), ssoOriginCheck, (req, res) => {
|
|
|
|
const {token, password} = req.data;
|
|
|
|
|
2019-01-22 17:29:44 +03:00
|
|
|
users.resetPassword({token, password}).then((member) => {
|
2018-12-11 09:47:44 +03:00
|
|
|
res.writeHead(200, {
|
|
|
|
'Set-Cookie': setCookie(member)
|
|
|
|
});
|
|
|
|
res.end();
|
|
|
|
}).catch(handleError(401, res));
|
|
|
|
});
|
|
|
|
|
2019-01-22 17:29:44 +03:00
|
|
|
/* users, email */
|
2018-12-11 09:47:44 +03:00
|
|
|
apiRouter.post('/signup', getData('name', 'email', 'password'), ssoOriginCheck, (req, res) => {
|
|
|
|
const {name, email, password} = req.data;
|
|
|
|
|
|
|
|
// @TODO this should attempt to reset password before creating member
|
2019-01-22 17:29:44 +03:00
|
|
|
users.create({name, email, password}).then((member) => {
|
2018-12-11 09:47:44 +03:00
|
|
|
res.writeHead(200, {
|
|
|
|
'Set-Cookie': setCookie(member)
|
|
|
|
});
|
|
|
|
res.end();
|
|
|
|
}).catch(handleError(400, res));
|
|
|
|
});
|
|
|
|
|
2019-01-22 17:29:44 +03:00
|
|
|
/* users, session */
|
2018-12-11 09:47:44 +03:00
|
|
|
apiRouter.post('/signin', getData('email', 'password'), ssoOriginCheck, (req, res) => {
|
|
|
|
const {email, password} = req.data;
|
|
|
|
|
2019-01-22 17:29:44 +03:00
|
|
|
users.validate({email, password}).then((member) => {
|
2018-12-11 09:47:44 +03:00
|
|
|
res.writeHead(200, {
|
|
|
|
'Set-Cookie': setCookie(member)
|
|
|
|
});
|
|
|
|
res.end();
|
|
|
|
}).catch(handleError(401, res));
|
|
|
|
});
|
|
|
|
|
2019-01-22 17:29:44 +03:00
|
|
|
/* session */
|
2018-12-14 09:56:31 +03:00
|
|
|
apiRouter.post('/signout', getData(), (req, res) => {
|
2018-12-11 09:47:44 +03:00
|
|
|
res.writeHead(200, {
|
|
|
|
'Set-Cookie': removeCookie()
|
|
|
|
});
|
|
|
|
res.end();
|
|
|
|
});
|
|
|
|
|
2019-01-22 17:29:44 +03:00
|
|
|
/* http */
|
2018-12-11 09:47:44 +03:00
|
|
|
const staticRouter = Router();
|
|
|
|
staticRouter.use('/static', static(require('path').join(__dirname, './static/auth/dist')));
|
Updated theme layer to use members-ssr (#10676)
* Removed support for cookies in members auth middleware
no-issue
The members middleware will no longer be supporting cookies, the cookie
will be handled by a new middleware specific for serverside rendering,
more informations can be found here:
https://paper.dropbox.com/doc/Members-Auth-II-4WP4vF6coMqDYbSMIajo5
* Removed members auth middleware from site app
no-issue
The site app no longer needs the members auth middleware as it doesn't
support cookies, and will be replaced by ssr specific middleware.
https://paper.dropbox.com/doc/Members-Auth-II-4WP4vF6coMqDYbSMIajo5
* Added comment for session_secret setting
no-issue
We are going to have multiple concepts of sessions, so adding a comment
here to be specific that this is for the Ghost Admin client
* Added theme_session_secret setting dynamic default
no-issue
Sessions for the theme layer will be signed, so we generate a random hex
string to use as a signing key
* Added getPublicConfig method
* Replaced export of httpHandler with POJO apiInstance
no-issue
This is mainly to reduce the public api, so it's easier to document.
* Renamed memberUserObject -> members
no-issue
Simplifies the interface, and is more inline with what we would want to export as an api library.
* Removed use of require options inside members
no-issue
This was too tight of a coupling between Ghost and Members
* Simplified apiInstance definition
no-issue
* Added getMember method to members api
* Added MembersSSR instance to members service
* Wired up routes for members ssr
* Updated members auth middleware to use getPublicConfig
* Removed publicKey static export from members service
* Used real session secret
no-issue
* Added DELETE /members/ssr handler
no-issue
This allows users to log out of the theme layer
* Fixed missing code property
no-issue
Ignition uses the statusCode property to forward status codes to call sites
* Removed superfluous error middleware
no-issue
Before we used generic JWT middleware which would reject, now the
middleware catches it's own error and doesn't error, thus this
middleware is unecessary.
* Removed console.logs
no-issue
* Updated token expirty to hardcoded 20 minutes
no-issue
This returns to our previous state of using short lived tokens, both for
security and simplicity.
* Removed hardcoded default member settings
no-issue
This is no longer needed, as defaults are in default-settings.json
* Removed stripe from default payment processor
no-issue
* Exported `getSiteUrl` method from url utils
no-issue
This keeps inline with newer naming conventions
* Updated how audience access control works
no-issue
Rather than being passed a function, members api now receives an object
which describes which origins have access to which audiences, and how
long those tokens should be allowed to work for. It also allows syntax
for default tokens where audience === origin requesting it. This can be
set to undefined or null to disable this functionality.
{
"http://site.com": {
"http://site.com": {
tokenLength: '5m'
},
"http://othersite.com": {
tokenLength: '1h'
}
},
"*": {
tokenLength: '30m'
}
}
* Updated members service to use access control feature
no-issue
This also cleans up a lot of unecessary variable definitions, and some
other minor cleanups.
* Added status code to auth pages html response
no-issue
This was missing, probably default but better to be explicit
* Updated gateway to have membersApiUrl from config
no-issue
Previously we were parsing the url, this was not very safe as we can
have Ghost hosted on a subdomain, and this would have failed.
* Added issuer to public config for members
no-issue
This can be used to request SSR tokens in the client
* Fixed path for gateway bundle
no-issue
* Updated settings model tests
no-issue
* Revert "Removed stripe from default payment processor"
This reverts commit 1d88d9b6d73a10091070bcc1b7f5779d071c7845.
* Revert "Removed hardcoded default member settings"
This reverts commit 9d899048ba7d4b272b9ac65a95a52af66b30914a.
* Installed @tryghost/members-ssr
* Fixed tests for settings model
2019-04-16 17:50:25 +03:00
|
|
|
staticRouter.get('/gateway', (req, res) => {
|
|
|
|
res.status(200).send(`
|
|
|
|
<script>
|
|
|
|
window.membersApiUrl = "${issuer}";
|
|
|
|
</script>
|
|
|
|
<script src="bundle.js"></script>
|
|
|
|
`);
|
|
|
|
});
|
|
|
|
staticRouter.get('/bundle.js', (req, res) => {
|
|
|
|
res.status(200).sendFile(require('path').join(__dirname, './static/gateway/bundle.js'));
|
|
|
|
});
|
2018-12-11 09:47:44 +03:00
|
|
|
staticRouter.get('/*', (req, res) => {
|
Updated theme layer to use members-ssr (#10676)
* Removed support for cookies in members auth middleware
no-issue
The members middleware will no longer be supporting cookies, the cookie
will be handled by a new middleware specific for serverside rendering,
more informations can be found here:
https://paper.dropbox.com/doc/Members-Auth-II-4WP4vF6coMqDYbSMIajo5
* Removed members auth middleware from site app
no-issue
The site app no longer needs the members auth middleware as it doesn't
support cookies, and will be replaced by ssr specific middleware.
https://paper.dropbox.com/doc/Members-Auth-II-4WP4vF6coMqDYbSMIajo5
* Added comment for session_secret setting
no-issue
We are going to have multiple concepts of sessions, so adding a comment
here to be specific that this is for the Ghost Admin client
* Added theme_session_secret setting dynamic default
no-issue
Sessions for the theme layer will be signed, so we generate a random hex
string to use as a signing key
* Added getPublicConfig method
* Replaced export of httpHandler with POJO apiInstance
no-issue
This is mainly to reduce the public api, so it's easier to document.
* Renamed memberUserObject -> members
no-issue
Simplifies the interface, and is more inline with what we would want to export as an api library.
* Removed use of require options inside members
no-issue
This was too tight of a coupling between Ghost and Members
* Simplified apiInstance definition
no-issue
* Added getMember method to members api
* Added MembersSSR instance to members service
* Wired up routes for members ssr
* Updated members auth middleware to use getPublicConfig
* Removed publicKey static export from members service
* Used real session secret
no-issue
* Added DELETE /members/ssr handler
no-issue
This allows users to log out of the theme layer
* Fixed missing code property
no-issue
Ignition uses the statusCode property to forward status codes to call sites
* Removed superfluous error middleware
no-issue
Before we used generic JWT middleware which would reject, now the
middleware catches it's own error and doesn't error, thus this
middleware is unecessary.
* Removed console.logs
no-issue
* Updated token expirty to hardcoded 20 minutes
no-issue
This returns to our previous state of using short lived tokens, both for
security and simplicity.
* Removed hardcoded default member settings
no-issue
This is no longer needed, as defaults are in default-settings.json
* Removed stripe from default payment processor
no-issue
* Exported `getSiteUrl` method from url utils
no-issue
This keeps inline with newer naming conventions
* Updated how audience access control works
no-issue
Rather than being passed a function, members api now receives an object
which describes which origins have access to which audiences, and how
long those tokens should be allowed to work for. It also allows syntax
for default tokens where audience === origin requesting it. This can be
set to undefined or null to disable this functionality.
{
"http://site.com": {
"http://site.com": {
tokenLength: '5m'
},
"http://othersite.com": {
tokenLength: '1h'
}
},
"*": {
tokenLength: '30m'
}
}
* Updated members service to use access control feature
no-issue
This also cleans up a lot of unecessary variable definitions, and some
other minor cleanups.
* Added status code to auth pages html response
no-issue
This was missing, probably default but better to be explicit
* Updated gateway to have membersApiUrl from config
no-issue
Previously we were parsing the url, this was not very safe as we can
have Ghost hosted on a subdomain, and this would have failed.
* Added issuer to public config for members
no-issue
This can be used to request SSR tokens in the client
* Fixed path for gateway bundle
no-issue
* Updated settings model tests
no-issue
* Revert "Removed stripe from default payment processor"
This reverts commit 1d88d9b6d73a10091070bcc1b7f5779d071c7845.
* Revert "Removed hardcoded default member settings"
This reverts commit 9d899048ba7d4b272b9ac65a95a52af66b30914a.
* Installed @tryghost/members-ssr
* Fixed tests for settings model
2019-04-16 17:50:25 +03:00
|
|
|
res.status(200).sendFile(require('path').join(__dirname, './static/auth/dist/index.html'));
|
2018-12-11 09:47:44 +03:00
|
|
|
});
|
|
|
|
|
2019-01-22 17:29:44 +03:00
|
|
|
/* http */
|
2018-12-11 09:47:44 +03:00
|
|
|
router.use('/api', apiRouter);
|
|
|
|
router.use('/static', staticRouter);
|
2019-01-22 17:29:44 +03:00
|
|
|
/* token */
|
2018-12-11 09:47:44 +03:00
|
|
|
router.get('/.well-known/jwks.json', (req, res) => {
|
2019-01-22 17:29:44 +03:00
|
|
|
getPublicKeys().then((jwks) => {
|
|
|
|
res.json(jwks);
|
2018-12-11 09:47:44 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
Updated theme layer to use members-ssr (#10676)
* Removed support for cookies in members auth middleware
no-issue
The members middleware will no longer be supporting cookies, the cookie
will be handled by a new middleware specific for serverside rendering,
more informations can be found here:
https://paper.dropbox.com/doc/Members-Auth-II-4WP4vF6coMqDYbSMIajo5
* Removed members auth middleware from site app
no-issue
The site app no longer needs the members auth middleware as it doesn't
support cookies, and will be replaced by ssr specific middleware.
https://paper.dropbox.com/doc/Members-Auth-II-4WP4vF6coMqDYbSMIajo5
* Added comment for session_secret setting
no-issue
We are going to have multiple concepts of sessions, so adding a comment
here to be specific that this is for the Ghost Admin client
* Added theme_session_secret setting dynamic default
no-issue
Sessions for the theme layer will be signed, so we generate a random hex
string to use as a signing key
* Added getPublicConfig method
* Replaced export of httpHandler with POJO apiInstance
no-issue
This is mainly to reduce the public api, so it's easier to document.
* Renamed memberUserObject -> members
no-issue
Simplifies the interface, and is more inline with what we would want to export as an api library.
* Removed use of require options inside members
no-issue
This was too tight of a coupling between Ghost and Members
* Simplified apiInstance definition
no-issue
* Added getMember method to members api
* Added MembersSSR instance to members service
* Wired up routes for members ssr
* Updated members auth middleware to use getPublicConfig
* Removed publicKey static export from members service
* Used real session secret
no-issue
* Added DELETE /members/ssr handler
no-issue
This allows users to log out of the theme layer
* Fixed missing code property
no-issue
Ignition uses the statusCode property to forward status codes to call sites
* Removed superfluous error middleware
no-issue
Before we used generic JWT middleware which would reject, now the
middleware catches it's own error and doesn't error, thus this
middleware is unecessary.
* Removed console.logs
no-issue
* Updated token expirty to hardcoded 20 minutes
no-issue
This returns to our previous state of using short lived tokens, both for
security and simplicity.
* Removed hardcoded default member settings
no-issue
This is no longer needed, as defaults are in default-settings.json
* Removed stripe from default payment processor
no-issue
* Exported `getSiteUrl` method from url utils
no-issue
This keeps inline with newer naming conventions
* Updated how audience access control works
no-issue
Rather than being passed a function, members api now receives an object
which describes which origins have access to which audiences, and how
long those tokens should be allowed to work for. It also allows syntax
for default tokens where audience === origin requesting it. This can be
set to undefined or null to disable this functionality.
{
"http://site.com": {
"http://site.com": {
tokenLength: '5m'
},
"http://othersite.com": {
tokenLength: '1h'
}
},
"*": {
tokenLength: '30m'
}
}
* Updated members service to use access control feature
no-issue
This also cleans up a lot of unecessary variable definitions, and some
other minor cleanups.
* Added status code to auth pages html response
no-issue
This was missing, probably default but better to be explicit
* Updated gateway to have membersApiUrl from config
no-issue
Previously we were parsing the url, this was not very safe as we can
have Ghost hosted on a subdomain, and this would have failed.
* Added issuer to public config for members
no-issue
This can be used to request SSR tokens in the client
* Fixed path for gateway bundle
no-issue
* Updated settings model tests
no-issue
* Revert "Removed stripe from default payment processor"
This reverts commit 1d88d9b6d73a10091070bcc1b7f5779d071c7845.
* Revert "Removed hardcoded default member settings"
This reverts commit 9d899048ba7d4b272b9ac65a95a52af66b30914a.
* Installed @tryghost/members-ssr
* Fixed tests for settings model
2019-04-16 17:50:25 +03:00
|
|
|
const apiInstance = {
|
|
|
|
staticRouter,
|
|
|
|
apiRouter
|
|
|
|
};
|
|
|
|
apiInstance.members = users;
|
|
|
|
apiInstance.getPublicConfig = function () {
|
|
|
|
return Promise.resolve({
|
|
|
|
publicKey,
|
|
|
|
issuer
|
|
|
|
});
|
|
|
|
};
|
|
|
|
apiInstance.getMember = function (id, token) {
|
|
|
|
return decodeToken(token).then(() => {
|
|
|
|
return users.get({id});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
apiInstance.reconfigureSettings = function (data) {
|
2019-02-26 06:09:16 +03:00
|
|
|
subscriptions = new Subscriptions(data.paymentConfig);
|
|
|
|
users = Users({
|
|
|
|
subscriptions,
|
|
|
|
createMember,
|
|
|
|
updateMember,
|
|
|
|
getMember,
|
|
|
|
validateMember,
|
|
|
|
sendEmail,
|
|
|
|
encodeToken,
|
|
|
|
listMembers,
|
|
|
|
decodeToken
|
|
|
|
});
|
|
|
|
siteConfig = data.siteConfig;
|
|
|
|
};
|
2018-12-11 09:47:44 +03:00
|
|
|
|
Updated theme layer to use members-ssr (#10676)
* Removed support for cookies in members auth middleware
no-issue
The members middleware will no longer be supporting cookies, the cookie
will be handled by a new middleware specific for serverside rendering,
more informations can be found here:
https://paper.dropbox.com/doc/Members-Auth-II-4WP4vF6coMqDYbSMIajo5
* Removed members auth middleware from site app
no-issue
The site app no longer needs the members auth middleware as it doesn't
support cookies, and will be replaced by ssr specific middleware.
https://paper.dropbox.com/doc/Members-Auth-II-4WP4vF6coMqDYbSMIajo5
* Added comment for session_secret setting
no-issue
We are going to have multiple concepts of sessions, so adding a comment
here to be specific that this is for the Ghost Admin client
* Added theme_session_secret setting dynamic default
no-issue
Sessions for the theme layer will be signed, so we generate a random hex
string to use as a signing key
* Added getPublicConfig method
* Replaced export of httpHandler with POJO apiInstance
no-issue
This is mainly to reduce the public api, so it's easier to document.
* Renamed memberUserObject -> members
no-issue
Simplifies the interface, and is more inline with what we would want to export as an api library.
* Removed use of require options inside members
no-issue
This was too tight of a coupling between Ghost and Members
* Simplified apiInstance definition
no-issue
* Added getMember method to members api
* Added MembersSSR instance to members service
* Wired up routes for members ssr
* Updated members auth middleware to use getPublicConfig
* Removed publicKey static export from members service
* Used real session secret
no-issue
* Added DELETE /members/ssr handler
no-issue
This allows users to log out of the theme layer
* Fixed missing code property
no-issue
Ignition uses the statusCode property to forward status codes to call sites
* Removed superfluous error middleware
no-issue
Before we used generic JWT middleware which would reject, now the
middleware catches it's own error and doesn't error, thus this
middleware is unecessary.
* Removed console.logs
no-issue
* Updated token expirty to hardcoded 20 minutes
no-issue
This returns to our previous state of using short lived tokens, both for
security and simplicity.
* Removed hardcoded default member settings
no-issue
This is no longer needed, as defaults are in default-settings.json
* Removed stripe from default payment processor
no-issue
* Exported `getSiteUrl` method from url utils
no-issue
This keeps inline with newer naming conventions
* Updated how audience access control works
no-issue
Rather than being passed a function, members api now receives an object
which describes which origins have access to which audiences, and how
long those tokens should be allowed to work for. It also allows syntax
for default tokens where audience === origin requesting it. This can be
set to undefined or null to disable this functionality.
{
"http://site.com": {
"http://site.com": {
tokenLength: '5m'
},
"http://othersite.com": {
tokenLength: '1h'
}
},
"*": {
tokenLength: '30m'
}
}
* Updated members service to use access control feature
no-issue
This also cleans up a lot of unecessary variable definitions, and some
other minor cleanups.
* Added status code to auth pages html response
no-issue
This was missing, probably default but better to be explicit
* Updated gateway to have membersApiUrl from config
no-issue
Previously we were parsing the url, this was not very safe as we can
have Ghost hosted on a subdomain, and this would have failed.
* Added issuer to public config for members
no-issue
This can be used to request SSR tokens in the client
* Fixed path for gateway bundle
no-issue
* Updated settings model tests
no-issue
* Revert "Removed stripe from default payment processor"
This reverts commit 1d88d9b6d73a10091070bcc1b7f5779d071c7845.
* Revert "Removed hardcoded default member settings"
This reverts commit 9d899048ba7d4b272b9ac65a95a52af66b30914a.
* Installed @tryghost/members-ssr
* Fixed tests for settings model
2019-04-16 17:50:25 +03:00
|
|
|
return apiInstance;
|
2018-12-11 09:47:44 +03:00
|
|
|
};
|