-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
385 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,94 @@ | ||
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify"; | ||
import { checkToken } from "../lib/jwt"; | ||
import { prisma } from "../prisma"; | ||
|
||
// Check Github Version | ||
// Check Github Version | ||
// Add outbound email provider | ||
// Email Verification | ||
// SSO Provider | ||
// Portal Locale | ||
// Feature Flags | ||
// Feature Flags | ||
|
||
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify"; | ||
import { checkToken } from "../lib/jwt"; | ||
import { prisma } from "../prisma"; | ||
|
||
export function configRoutes(fastify: FastifyInstance) { | ||
// Check if SSO is enabled | ||
fastify.get( | ||
"/api/v1/config/sso/enabled", | ||
|
||
async (request: FastifyRequest, reply: FastifyReply) => { | ||
const bearer = request.headers.authorization!.split(" ")[1]; | ||
const token = checkToken(bearer); | ||
|
||
if (token) { | ||
const config = await prisma.config.findFirst(); | ||
|
||
//@ts-expect-error | ||
const { sso_active } = config; | ||
|
||
if (sso_active) { | ||
const provider = await prisma.provider.findFirst({}); | ||
|
||
reply.send({ | ||
success: true, | ||
sso: sso_active, | ||
provider: provider, | ||
}); | ||
} | ||
|
||
reply.send({ | ||
success: true, | ||
sso: sso_active, | ||
}); | ||
} | ||
} | ||
); | ||
|
||
// Update SSO Provider Settings | ||
fastify.post( | ||
"/api/v1/config/sso/provider", | ||
|
||
async (request: FastifyRequest, reply: FastifyReply) => { | ||
const bearer = request.headers.authorization!.split(" ")[1]; | ||
const token = checkToken(bearer); | ||
|
||
if (token) { | ||
const { | ||
name, | ||
client_id, | ||
client_secret, | ||
redirect_uri, | ||
tenantId, | ||
issuer, | ||
}: any = request.body; | ||
|
||
const conf = await prisma.config.findFirst(); | ||
|
||
//update config to true | ||
await prisma.config.update({ | ||
where: { id: conf!.id }, | ||
data: { | ||
sso_active: true, | ||
sso_provider: name, | ||
}, | ||
}); | ||
|
||
// UPDATE PROVIDER | ||
await prisma.provider.create({ | ||
data: { | ||
name: name, | ||
clientId: client_id, | ||
clientSecret: client_secret, | ||
active: true, | ||
redirectUri: redirect_uri, | ||
tenantId: tenantId, | ||
issuer: issuer, | ||
}, | ||
}); | ||
|
||
reply.send({ | ||
success: true, | ||
message: "SSO Provider updated!", | ||
}); | ||
} | ||
} | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.