removed oAuth endpoint from dispatch, started oAuth endpoints for moodle
This commit is contained in:
@@ -1,48 +1,48 @@
|
||||
'use client';
|
||||
import { redirect, useSearchParams } from 'next/navigation';
|
||||
import { Service } from '../page';
|
||||
import { generateToken } from './action';
|
||||
import { useSession } from 'next-auth/react';
|
||||
"use client";
|
||||
import { redirect, useSearchParams } from "next/navigation";
|
||||
import { Service } from "../page";
|
||||
import { generateToken } from "./action";
|
||||
import { useSession } from "next-auth/react";
|
||||
|
||||
export const Authorize = ({ service }: { service: Service }) => {
|
||||
const searchParams = useSearchParams();
|
||||
const legitimeUrl = service.approvedUrls.some((url) =>
|
||||
searchParams.get('redirect_uri')?.startsWith(url)
|
||||
);
|
||||
const { data: session } = useSession();
|
||||
console.log(session);
|
||||
if (!session)
|
||||
redirect('/login?redirect=' + encodeURIComponent(window.location.href));
|
||||
if (!legitimeUrl)
|
||||
return (
|
||||
<div className="card-body">
|
||||
<h1 className="text-4xl font-bold">Unerlaubter Zugriff</h1>
|
||||
<p>Du greifst von einem nicht genehmigtem Server auf diese URL zu</p>
|
||||
</div>
|
||||
);
|
||||
const searchParams = useSearchParams();
|
||||
const legitimeUrl = service.approvedUrls.some((url) =>
|
||||
searchParams.get("redirect_uri")?.startsWith(url),
|
||||
);
|
||||
const { data: session } = useSession();
|
||||
console.log(session);
|
||||
if (!session)
|
||||
redirect("/login?redirect=" + encodeURIComponent(window.location.href));
|
||||
if (!legitimeUrl)
|
||||
return (
|
||||
<div className="card-body">
|
||||
<h1 className="text-4xl font-bold">Unerlaubter Zugriff</h1>
|
||||
<p>Du greifst von einem nicht genehmigtem Server auf diese URL zu</p>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<form className="card-body" onSubmit={(e) => e.preventDefault()}>
|
||||
<h1 className="text-4xl font-bold">Zugriff zulassen</h1>
|
||||
<p>
|
||||
Die Anwendung <strong>{service.name}</strong> möchte auf deine Daten
|
||||
zugreifen.
|
||||
</p>
|
||||
<div className="space-x-4">
|
||||
<button type="button" className="btn">
|
||||
Verweigern
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
className="btn btn-primary"
|
||||
onClick={async () => {
|
||||
const code = await generateToken(service);
|
||||
window.location.href = `${searchParams.get('redirect_uri')}?code=${code?.accessToken}`;
|
||||
}}
|
||||
>
|
||||
Zulassen
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
return (
|
||||
<form className="card-body" onSubmit={(e) => e.preventDefault()}>
|
||||
<h1 className="text-4xl font-bold">Zugriff zulassen</h1>
|
||||
<p>
|
||||
Die Anwendung <strong>{service.name}</strong> möchte auf deine Daten
|
||||
zugreifen.
|
||||
</p>
|
||||
<div className="space-x-4">
|
||||
<button type="button" className="btn">
|
||||
Verweigern
|
||||
</button>
|
||||
<button
|
||||
type="submit"
|
||||
className="btn btn-primary"
|
||||
onClick={async () => {
|
||||
const code = await generateToken(service);
|
||||
window.location.href = `${searchParams.get("redirect_uri")}?code=${code?.accessToken}`;
|
||||
}}
|
||||
>
|
||||
Zulassen
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,32 +1,39 @@
|
||||
import { Authorize } from './_components/Authorize';
|
||||
import { Authorize } from "./_components/Authorize";
|
||||
|
||||
export const services = [
|
||||
{
|
||||
id: '123456',
|
||||
service: 'dispatch',
|
||||
name: 'Leitstellendisposition',
|
||||
approvedUrls: ['http://localhost:3001'],
|
||||
},
|
||||
{
|
||||
id: '789456',
|
||||
service: 'desktop',
|
||||
name: 'Desktop client',
|
||||
approvedUrls: ['var'],
|
||||
},
|
||||
{
|
||||
id: "1",
|
||||
service: "dispatch",
|
||||
name: "Leitstellendisposition",
|
||||
approvedUrls: ["http://localhost:3001"],
|
||||
},
|
||||
{
|
||||
id: "2",
|
||||
service: "desktop",
|
||||
name: "Desktop client",
|
||||
approvedUrls: ["var"],
|
||||
},
|
||||
{
|
||||
id: "3",
|
||||
secret: "d0f3e4e4",
|
||||
service: "moodle",
|
||||
name: "Moodle",
|
||||
approvedUrls: ["https://moodle.virtualairrescue.com"],
|
||||
},
|
||||
];
|
||||
export type Service = (typeof services)[number];
|
||||
|
||||
export default async ({
|
||||
searchParams,
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
|
||||
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
|
||||
}) => {
|
||||
const { service: serviceId } = await searchParams;
|
||||
const service = services.find((service) => service.id === serviceId);
|
||||
const { service: serviceId } = await searchParams;
|
||||
const service = services.find((service) => service.id === serviceId);
|
||||
|
||||
if (!service) {
|
||||
return <div>Service not found</div>;
|
||||
}
|
||||
if (!service) {
|
||||
return <div>Service not found</div>;
|
||||
}
|
||||
|
||||
return <Authorize service={service} />;
|
||||
return <Authorize service={service} />;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user