Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Boilerplate OAuth website <=> inference (#2127)
Refs #2101 Use the website's backend as a callback url for login to discord and github, so that the website also knows the token. To use this, you need to configure your discord oauth provider to use the url: `http://localhost:3000/api/inference_auth/discord`, I used the same provider I use for logging in to the website and it worked like a charm. github also: `http://localhost:3000/api/inference_auth` or `http://localhost:3000/api/inference_auth/gihtub`, both should work since github allows sub paths. you need to set these 4 env variables for the inference server: ``` AUTH_DISCORD_CLIENT_ID AUTH_DISCORD_CLIENT_SECRET AUTH_GITHUB_CLIENT_ID AUTH_GITHUB_CLIENT_SECRET ``` then you can navigate to ``` localhost:8000/auth/login/github localhost:8000/auth/login/discord ```
- Loading branch information
Showing
8 changed files
with
42 additions
and
14 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
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,16 @@ | ||
import axios from "axios"; | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
import { InferenceTokenResponse } from "src/types/Chat"; | ||
|
||
export default async function inferenceAuthCallback(req: NextApiRequest, res: NextApiResponse) { | ||
const { code, parts } = req.query; | ||
console.log(req.query); | ||
if (!Array.isArray(parts) || parts.length !== 1) { | ||
return res.status(400).end(); | ||
} | ||
const [provider] = parts as string[]; | ||
const url = process.env.INFERENCE_SERVER_HOST + `/auth/callback/${provider}?code=${code}`; | ||
const { data } = await axios<InferenceTokenResponse>(url); | ||
console.log(data); | ||
return res.send(data); | ||
} |
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