Implementing basic auth_grant
This commit is contained in:
23
src/models/grants.ts
Normal file
23
src/models/grants.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import DB from "../database";
|
||||
import { ModelDataBase } from "@hibas123/safe_mongo/lib/model";
|
||||
import { ObjectID } from "mongodb";
|
||||
|
||||
export interface IGrant extends ModelDataBase {
|
||||
user: ObjectID;
|
||||
client: ObjectID;
|
||||
permissions: ObjectID[];
|
||||
}
|
||||
|
||||
const Grant = DB.addModel<IGrant>({
|
||||
name: "grant",
|
||||
versions: [{
|
||||
migration: () => { },
|
||||
schema: {
|
||||
user: { type: ObjectID },
|
||||
client: { type: ObjectID },
|
||||
permissions: { type: ObjectID, array: true }
|
||||
}
|
||||
}]
|
||||
})
|
||||
|
||||
export default Grant;
|
@ -1,12 +1,12 @@
|
||||
import DB from "../database";
|
||||
import { ModelDataBase } from "@hibas123/safe_mongo/lib/model";
|
||||
import { ObjectID } from "mongodb";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
export interface IPermission extends ModelDataBase {
|
||||
name: string;
|
||||
description: string;
|
||||
client: ObjectID;
|
||||
grant_type: "user" | "client";
|
||||
}
|
||||
|
||||
const Permission = DB.addModel<IPermission>({
|
||||
@ -18,7 +18,15 @@ const Permission = DB.addModel<IPermission>({
|
||||
description: { type: String },
|
||||
client: { type: ObjectID }
|
||||
}
|
||||
}, {
|
||||
migration: (old) => { old.grant_type = "user" },
|
||||
schema: {
|
||||
name: { type: String },
|
||||
description: { type: String },
|
||||
client: { type: ObjectID },
|
||||
grant_type: { type: String, default: "user" }
|
||||
}
|
||||
}]
|
||||
})
|
||||
|
||||
export default Permission;
|
||||
export default Permission;
|
||||
|
Reference in New Issue
Block a user