Open philippewinter opened 4 years ago
Same here
import { Document, model, Schema } from "mongoose";
import encrypt from "mongoose-encryption";
import mongooseHidden from "mongoose-hidden";
`
export interface ISettings {
userId: string;
mapbox: {
user: string;
publicToken: string;
privateToken: string;
};
}
export type SettingsModel = ISettings & Document;
export const SettingsSchema = new Schema(
{
userId: { type: Schema.Types.ObjectId, ref: "User", required: true },
mapbox: {
user: String,
publicToken: String,
privateToken: String,
},
},
{
timestamps: true,
},
);
SettingsSchema.set("toJSON", {
virtuals: true,
});
SettingsSchema.plugin(encrypt, {
secret: "dupa",
encryptedFields: ["mapbox.privateToken"],
});
SettingsSchema.plugin(mongooseHidden({ hidden: { __t: true } }));
export const Settings = model<SettingsModel>("Settings", SettingsSchema);
Then simple mongoose.find gives me "Authentication failed".
I trakced that function authenticateSync gives me error because
var authentic = bufferEqual(basicAC, expectedHMAC); // Here bufferEqual returns false
if (!authentic){
throw new Error('Authentication failed');
}
@karenpommeroy I wonder if this is related to the mongooseHidden
plugin you added. If you remove that, or perhaps simply reverse the order in which you add the plugins, does that solve the issue?
For the original issue cited, aggregations in general aren't a tested aspect of this package. In general, I'd expect they might work if the fields involved aren't encrypted. However, in this particular case, the entire quotes
subdocument is marked to be authenticated, but then only some of its fields are returned in the aggregation, which means authentication cannot be performed. Hence, the error returned!
Hi,
I'm trying to use aggregate on initial access to a document, I have encrypted the subdocument. Error: UnhandledPromiseRejectionWarning: Error: Authentication failed: Only some authenticated fields were selected by the query. Either all or none of the authenticated fields (quotes,_ct,_ac) should be selected for proper authentication.
My Code: