Finished Moodle oAuth service

READ Moodle section in README file
This commit is contained in:
PxlLoewe
2025-02-27 00:32:44 +01:00
parent b81bab1dc2
commit 9366f8f6b4
8 changed files with 149 additions and 50 deletions

View File

@@ -10,7 +10,6 @@ export const Authorize = ({ service }: { service: Service }) => {
searchParams.get("redirect_uri")?.startsWith(url),
);
const { data: session } = useSession();
console.log(session);
if (!session)
redirect("/login?redirect=" + encodeURIComponent(window.location.href));
if (!legitimeUrl)
@@ -37,7 +36,14 @@ export const Authorize = ({ service }: { service: Service }) => {
className="btn btn-primary"
onClick={async () => {
const code = await generateToken(service);
window.location.href = `${searchParams.get("redirect_uri")}?code=${code?.accessToken}`;
const url = new URL(searchParams.get("redirect_uri") as string);
url.searchParams.append("code", code?.accessToken as string);
url.searchParams.append(
"state",
searchParams.get("state") as string,
);
window.location.href = url.href;
}}
>
Zulassen

View File

@@ -18,7 +18,10 @@ export const services = [
secret: "d0f3e4e4",
service: "moodle",
name: "Moodle",
approvedUrls: ["https://moodle.virtualairrescue.com"],
approvedUrls: [
"http://localhost:8081",
"https://moodle.virtualairrescue.com",
],
},
];
export type Service = (typeof services)[number];
@@ -28,8 +31,11 @@ export default async ({
}: {
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
}) => {
const { service: serviceId } = await searchParams;
const service = services.find((service) => service.id === serviceId);
const { service: serviceId, client_id: clientId } = await searchParams;
const service = services.find(
(service) => service.id === serviceId || service.id === clientId,
);
if (!service) {
return <div>Service not found</div>;