mirror of
https://github.com/wassname/talk.git
synced 2026-09-10 12:43:11 +08:00
[CORL-750] SSO Migration Script Bug (#2715)
* fix: fixed bug with sso migration script * feat: refactored sso schema * fix: resolved issue with data race and migration/install ordering
This commit is contained in:
@@ -47,7 +47,7 @@ export async function createInvite(
|
||||
};
|
||||
|
||||
// Insert it into the database. This may throw an error.
|
||||
await collection(mongo).insert(invite);
|
||||
await collection(mongo).insertOne(invite);
|
||||
|
||||
return invite;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Omit, RequireProperty } from "coral-common/types";
|
||||
import { Omit } from "coral-common/types";
|
||||
|
||||
import {
|
||||
GQLAuth,
|
||||
@@ -46,30 +46,27 @@ export interface SSOKey {
|
||||
kid: string;
|
||||
|
||||
/**
|
||||
* secret is the actual underlying secret used to verify the tokens with. When
|
||||
* this is not available, it indicates that the token secret was deleted.
|
||||
* secret is the actual underlying secret used to verify the tokens with.
|
||||
*/
|
||||
secret?: string;
|
||||
secret: string;
|
||||
|
||||
/**
|
||||
* createdAt is the time that this key was created at.
|
||||
* createdAt is the date that the key was created at.
|
||||
*/
|
||||
createdAt: Date;
|
||||
|
||||
/**
|
||||
* deprecateAt when provided is the time that the token should no longer be
|
||||
* valid at.
|
||||
* rotatedAt is the time that the token was rotated out.
|
||||
*/
|
||||
deprecateAt?: Date;
|
||||
rotatedAt?: Date;
|
||||
|
||||
/**
|
||||
* deletedAt is the timestamp that the token was revoked.
|
||||
* inactiveAt is the date that the token can no longer be used to validate
|
||||
* tokens.
|
||||
*/
|
||||
deletedAt?: Date;
|
||||
inactiveAt?: Date;
|
||||
}
|
||||
|
||||
export type RequiredSSOKey = RequireProperty<SSOKey, "secret">;
|
||||
|
||||
export interface SSOAuthIntegration {
|
||||
enabled: boolean;
|
||||
allowRegistration: boolean;
|
||||
|
||||
@@ -199,7 +199,7 @@ export async function createTenant(
|
||||
};
|
||||
|
||||
// Insert the Tenant into the database.
|
||||
await collection(mongo).insert(tenant);
|
||||
await collection(mongo).insertOne(tenant);
|
||||
|
||||
return tenant;
|
||||
}
|
||||
@@ -306,18 +306,20 @@ export async function createTenantSSOKey(mongo: Db, id: string, now: Date) {
|
||||
return result.value || null;
|
||||
}
|
||||
|
||||
export async function deprecateTenantSSOKey(
|
||||
export async function rotateTenantSSOKey(
|
||||
mongo: Db,
|
||||
id: string,
|
||||
kid: string,
|
||||
deprecateAt: Date
|
||||
inactiveAt: Date,
|
||||
now: Date
|
||||
) {
|
||||
// Update the tenant.
|
||||
const result = await collection(mongo).findOneAndUpdate(
|
||||
{ id },
|
||||
{
|
||||
$set: {
|
||||
"auth.integrations.sso.keys.$[keys].deprecateAt": deprecateAt,
|
||||
"auth.integrations.sso.keys.$[keys].inactiveAt": inactiveAt,
|
||||
"auth.integrations.sso.keys.$[keys].rotatedAt": now,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user