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>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user