mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-01-16 23:00:51 +00:00
fix: Update GitHub callback URL in documentation and API to use state parameter
This commit is contained in:
parent
467d35889f
commit
ffcfa93ed3
2 changed files with 35 additions and 11 deletions
|
|
@ -26,20 +26,45 @@ export default class GitHubAPI {
|
|||
/*
|
||||
* GitHub App installation callback
|
||||
* This is called after a user installs the GitHub App
|
||||
* The state parameter contains base64 encoded JSON with projectId and userId
|
||||
*/
|
||||
router.get(
|
||||
"/github/auth/:projectId/:userId/callback",
|
||||
"/github/auth/callback",
|
||||
async (req: ExpressRequest, res: ExpressResponse) => {
|
||||
try {
|
||||
const projectId: string | undefined =
|
||||
req.params["projectId"]?.toString();
|
||||
const userId: string | undefined = req.params["userId"]?.toString();
|
||||
// GitHub sends state parameter back which contains projectId and userId
|
||||
const state: string | undefined = req.query["state"]?.toString();
|
||||
|
||||
if (!state) {
|
||||
return Response.sendErrorResponse(
|
||||
req,
|
||||
res,
|
||||
new BadDataException("State parameter is required"),
|
||||
);
|
||||
}
|
||||
|
||||
// Decode the state parameter to get projectId and userId
|
||||
let projectId: string | undefined;
|
||||
let userId: string | undefined;
|
||||
|
||||
try {
|
||||
const decodedState: { projectId?: string; userId?: string } =
|
||||
JSON.parse(Buffer.from(state, "base64").toString("utf-8"));
|
||||
projectId = decodedState.projectId;
|
||||
userId = decodedState.userId;
|
||||
} catch {
|
||||
return Response.sendErrorResponse(
|
||||
req,
|
||||
res,
|
||||
new BadDataException("Invalid state parameter"),
|
||||
);
|
||||
}
|
||||
|
||||
if (!projectId) {
|
||||
return Response.sendErrorResponse(
|
||||
req,
|
||||
res,
|
||||
new BadDataException("Project ID is required"),
|
||||
new BadDataException("Project ID is required in state"),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -47,7 +72,7 @@ export default class GitHubAPI {
|
|||
return Response.sendErrorResponse(
|
||||
req,
|
||||
res,
|
||||
new BadDataException("User ID is required"),
|
||||
new BadDataException("User ID is required in state"),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +113,7 @@ export default class GitHubAPI {
|
|||
|
||||
// Initiate GitHub App installation
|
||||
router.get(
|
||||
"/github/auth/:projectId/:userId/install",
|
||||
"/github/auth/install",
|
||||
async (req: ExpressRequest, res: ExpressResponse) => {
|
||||
try {
|
||||
if (!GitHubAppClientId) {
|
||||
|
|
@ -102,8 +127,8 @@ export default class GitHubAPI {
|
|||
}
|
||||
|
||||
const projectId: string | undefined =
|
||||
req.params["projectId"]?.toString();
|
||||
const userId: string | undefined = req.params["userId"]?.toString();
|
||||
req.query["projectId"]?.toString();
|
||||
const userId: string | undefined = req.query["userId"]?.toString();
|
||||
|
||||
if (!projectId || !userId) {
|
||||
return Response.sendErrorResponse(
|
||||
|
|
|
|||
|
|
@ -20,8 +20,7 @@ To integrate GitHub with your self-hosted OneUptime instance, you need to create
|
|||
3. Fill out the registration form:
|
||||
- **GitHub App name:** OneUptime (or any unique name)
|
||||
- **Homepage URL:** `https://your-oneuptime-domain.com`
|
||||
- **Callback URL:** `https://your-oneuptime-domain.com/api/github/auth/:projectId/:userId/callback`
|
||||
- Note: The `:projectId` and `:userId` are placeholders that will be dynamically replaced
|
||||
- **Callback URL:** `https://your-oneuptime-domain.com/api/github/auth/callback`
|
||||
- **Setup URL (optional):** Leave empty
|
||||
- **Webhook URL:** `https://your-oneuptime-domain.com/api/github/webhook`
|
||||
- **Webhook secret:** Generate a secure random string (save this for later)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue