-
Notifications
You must be signed in to change notification settings - Fork 16
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
1 parent
f523464
commit aa6ec1a
Showing
12 changed files
with
240 additions
and
128 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
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
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,36 @@ | ||
import { getKafkaClusters } from "@/api/kafka/actions"; | ||
import { redirect } from "@/navigation"; | ||
import { getCsrfToken, getProviders } from "next-auth/react"; | ||
import { SignInPage } from "./SignInPage"; | ||
|
||
export default async function SignIn({ | ||
searchParams, | ||
params, | ||
}: { | ||
searchParams?: { callbackUrl?: string }; | ||
params: { kafkaId?: string }; | ||
}) { | ||
return <SignInPage callbackUrl={searchParams?.callbackUrl ?? "/"} />; | ||
const providers = await getProviders(); | ||
const clusters = await getKafkaClusters(); | ||
const cluster = clusters.find((c) => c.id === params.kafkaId); | ||
if (cluster) { | ||
const authMethod = cluster.meta.authentication; | ||
console.log("???", authMethod); | ||
if (authMethod && authMethod.method !== "anonymous") { | ||
return ( | ||
<SignInPage | ||
provider={ | ||
authMethod?.method === "basic" ? "credentials" : "oauth-token" | ||
} | ||
callbackUrl={ | ||
searchParams?.callbackUrl ?? `/kafka/${params.kafkaId}/overview` | ||
} | ||
hasMultipleClusters={clusters.length > 1} | ||
/> | ||
); | ||
} else { | ||
return <>TODO</>; | ||
} | ||
} | ||
return redirect("/"); | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { getKafkaClusters } from "@/api/kafka/actions"; | ||
import { AuthOptions } from "next-auth"; | ||
import CredentialsProvider from "next-auth/providers/credentials"; | ||
import { Provider } from "next-auth/providers/index"; | ||
|
||
export function makeOauthTokenProvider(tokenUrl: string): Provider { | ||
const provider = CredentialsProvider({ | ||
// The name to display on the sign in form (e.g. 'Sign in with...') | ||
name: "OAuth token", | ||
id: "oauth-token", | ||
|
||
credentials: { | ||
clientId: { label: "Client ID", type: "text" }, | ||
secret: { label: "Client Secret", type: "password" }, | ||
}, | ||
|
||
async authorize(credentials) { | ||
console.log({ credentials }); | ||
// try the username/password combo against the getKafkaCluster API call | ||
// if we get a response, then we can assume the credentials are correct | ||
const { clientId, secret } = credentials ?? {}; | ||
try { | ||
if (clientId && secret) { | ||
const params = new URLSearchParams(); | ||
params.append("client_id", clientId); | ||
params.append("client_secret", secret); | ||
params.append("grant_type", "client_credentials"); | ||
|
||
const res = await fetch(tokenUrl, { | ||
cache: "no-cache", | ||
body: params, | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
}, | ||
}); | ||
const data = await res.json(); | ||
const accessToken = data.access_token as string; | ||
|
||
if (res.status === 200 && accessToken) { | ||
return { id: "1", name: clientId, accessToken }; | ||
} | ||
} | ||
} catch {} | ||
// store the credentials in the session | ||
// if we didn't get a successful response, the credentials are wrong | ||
return null; | ||
}, | ||
}); | ||
|
||
return provider; | ||
} |
Oops, something went wrong.