mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 15:27:27 +00:00
add back user populate
This commit is contained in:
+11
-11
@@ -148,7 +148,7 @@ const getAuthSTDPayload = async ({
|
|||||||
if (!isMatch) throw UnauthorizedRequestError({
|
if (!isMatch) throw UnauthorizedRequestError({
|
||||||
message: 'Failed to authenticate service token'
|
message: 'Failed to authenticate service token'
|
||||||
});
|
});
|
||||||
|
|
||||||
serviceTokenData = await ServiceTokenData
|
serviceTokenData = await ServiceTokenData
|
||||||
.findOneAndUpdate({
|
.findOneAndUpdate({
|
||||||
_id: new Types.ObjectId(TOKEN_IDENTIFIER)
|
_id: new Types.ObjectId(TOKEN_IDENTIFIER)
|
||||||
@@ -157,8 +157,8 @@ const getAuthSTDPayload = async ({
|
|||||||
}, {
|
}, {
|
||||||
new: true
|
new: true
|
||||||
})
|
})
|
||||||
.select('+encryptedKey +iv +tag');
|
.select('+encryptedKey +iv +tag').populate('user');
|
||||||
|
|
||||||
if (!serviceTokenData) throw ServiceTokenDataNotFoundError({ message: 'Failed to find service token data' });
|
if (!serviceTokenData) throw ServiceTokenDataNotFoundError({ message: 'Failed to find service token data' });
|
||||||
|
|
||||||
return serviceTokenData;
|
return serviceTokenData;
|
||||||
@@ -176,20 +176,20 @@ const getAuthSAAKPayload = async ({
|
|||||||
authTokenValue: string;
|
authTokenValue: string;
|
||||||
}) => {
|
}) => {
|
||||||
const [_, TOKEN_IDENTIFIER, TOKEN_SECRET] = <[string, string, string]>authTokenValue.split('.', 3);
|
const [_, TOKEN_IDENTIFIER, TOKEN_SECRET] = <[string, string, string]>authTokenValue.split('.', 3);
|
||||||
|
|
||||||
const serviceAccount = await ServiceAccount.findById(
|
const serviceAccount = await ServiceAccount.findById(
|
||||||
Buffer.from(TOKEN_IDENTIFIER, 'base64').toString('hex')
|
Buffer.from(TOKEN_IDENTIFIER, 'base64').toString('hex')
|
||||||
).select('+secretHash');
|
).select('+secretHash');
|
||||||
|
|
||||||
if (!serviceAccount) {
|
if (!serviceAccount) {
|
||||||
throw ServiceAccountNotFoundError({ message: 'Failed to find service account' });
|
throw ServiceAccountNotFoundError({ message: 'Failed to find service account' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await bcrypt.compare(TOKEN_SECRET, serviceAccount.secretHash);
|
const result = await bcrypt.compare(TOKEN_SECRET, serviceAccount.secretHash);
|
||||||
if (!result) throw UnauthorizedRequestError({
|
if (!result) throw UnauthorizedRequestError({
|
||||||
message: 'Failed to authenticate service account access key'
|
message: 'Failed to authenticate service account access key'
|
||||||
});
|
});
|
||||||
|
|
||||||
return serviceAccount;
|
return serviceAccount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,7 +208,7 @@ const getAuthAPIKeyPayload = async ({
|
|||||||
|
|
||||||
let apiKeyData = await APIKeyData
|
let apiKeyData = await APIKeyData
|
||||||
.findById(TOKEN_IDENTIFIER, '+secretHash +expiresAt')
|
.findById(TOKEN_IDENTIFIER, '+secretHash +expiresAt')
|
||||||
.populate<{user: IUser}>('user', '+publicKey');
|
.populate<{ user: IUser }>('user', '+publicKey');
|
||||||
|
|
||||||
if (!apiKeyData) {
|
if (!apiKeyData) {
|
||||||
throw APIKeyDataNotFoundError({ message: 'Failed to find API key data' });
|
throw APIKeyDataNotFoundError({ message: 'Failed to find API key data' });
|
||||||
@@ -232,13 +232,13 @@ const getAuthAPIKeyPayload = async ({
|
|||||||
}, {
|
}, {
|
||||||
new: true
|
new: true
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!apiKeyData) {
|
if (!apiKeyData) {
|
||||||
throw APIKeyDataNotFoundError({ message: 'Failed to find API key data' });
|
throw APIKeyDataNotFoundError({ message: 'Failed to find API key data' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await User.findById(apiKeyData.user).select('+publicKey');
|
const user = await User.findById(apiKeyData.user).select('+publicKey');
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw AccountNotFoundError({
|
throw AccountNotFoundError({
|
||||||
message: 'Failed to find user'
|
message: 'Failed to find user'
|
||||||
|
|||||||
Reference in New Issue
Block a user