Start SCIM functionality

This commit is contained in:
Tuan Dang
2024-02-08 15:54:20 -08:00
parent 70e083bae0
commit d5064fe75a
12 changed files with 300 additions and 3 deletions
@@ -33,6 +33,10 @@ export type TAuthMode =
actor: ActorType.IDENTITY;
identityId: string;
identityName: string;
}
| {
authMode: AuthMode.SCIM_TOKEN;
actor: ActorType.SCIM_IDP;
};
const extractAuth = async (req: FastifyRequest, jwtSecret: string) => {
@@ -53,6 +57,7 @@ const extractAuth = async (req: FastifyRequest, jwtSecret: string) => {
}
const decodedToken = jwt.verify(authTokenValue, jwtSecret) as JwtPayload;
switch (decodedToken.authTokenType) {
case AuthTokenType.ACCESS_TOKEN:
return {
@@ -68,6 +73,12 @@ const extractAuth = async (req: FastifyRequest, jwtSecret: string) => {
token: decodedToken as TIdentityAccessTokenJwtPayload,
actor: ActorType.IDENTITY
} as const;
case AuthTokenType.SCIM_TOKEN:
return {
authMode: AuthMode.SCIM_TOKEN,
token: decodedToken,
actor: ActorType.SCIM_IDP
} as const;
default:
return { authMode: null, token: null } as const;
}
@@ -111,6 +122,10 @@ export const injectIdentity = fp(async (server: FastifyZodProvider) => {
req.auth = { authMode: AuthMode.API_KEY as const, userId: user.id, actor, user };
break;
}
case AuthMode.SCIM_TOKEN: {
req.auth = { authMode: AuthMode.SCIM_TOKEN, actor };
break;
}
default:
throw new UnauthorizedError({ name: "Unknown token strategy" });
}