mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Fixed source attribution for staff token API requests
closes https://github.com/TryGhost/Toolbox/issues/386 - When the API request was made using staff token the source attribution was "user" instead of "api". Misattribution caused ripple effects in limit service. - The fix also adds a new combination of data available on the `req` object - both `user` and `api_key` can be present when the request is done using a staff (user) token. Having both pieces of data on the request object gives more context for business logic, did not find a good reason to keep it "pure" with either `api_key` or `user` property.
This commit is contained in:
parent
6121451b5d
commit
02a0fd5a32
3 changed files with 3 additions and 6 deletions
|
@ -181,9 +181,6 @@ const authenticateWithToken = async (req, res, next, {token, JWT_OPTIONS}) => {
|
|||
);
|
||||
|
||||
req.user = user;
|
||||
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
// store the api key on the request for later checks and logging
|
||||
|
|
|
@ -105,10 +105,10 @@ module.exports = class MemberRepository {
|
|||
source = 'import';
|
||||
} else if (context.internal) {
|
||||
source = 'system';
|
||||
} else if (context.user) {
|
||||
source = 'admin';
|
||||
} else if (context.api_key) {
|
||||
source = 'api';
|
||||
} else if (context.user) {
|
||||
source = 'admin';
|
||||
} else {
|
||||
source = 'member';
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ describe('MemberRepository', function () {
|
|||
user: true,
|
||||
api_key: true
|
||||
});
|
||||
assert.equal(source, 'admin');
|
||||
assert.equal(source, 'api');
|
||||
|
||||
source = repo._resolveContextSource({
|
||||
api_key: true
|
||||
|
|
Loading…
Add table
Reference in a new issue