👔 (oauth) add callback URI options
provides the option to define a callback URI following a request from the frontend; if not defined, it will automatically use the backend's default URI.
This commit is contained in:
@ -34,7 +34,7 @@ DATABASE_URL=
|
|||||||
|
|
||||||
GITHUB_CLIENT_ID=
|
GITHUB_CLIENT_ID=
|
||||||
GITHUB_CLIENT_SECRET=
|
GITHUB_CLIENT_SECRET=
|
||||||
GITHUB_CLIENT_CALLBACK=
|
GITHUB_DEFAULT_CALLBACK=
|
||||||
|
|
||||||
GOOGLE_CLIENT_ID=
|
GOOGLE_CLIENT_ID=
|
||||||
GOOGLE_CLIENT_SECRET=
|
GOOGLE_CLIENT_SECRET=
|
||||||
|
|||||||
@ -2,12 +2,14 @@ import { Context } from "elysia";
|
|||||||
import { returnReadResponse } from "../../../helpers/callback/httpResponse";
|
import { returnReadResponse } from "../../../helpers/callback/httpResponse";
|
||||||
import { githubRequestService } from "../services/http/githubRequest.service";
|
import { githubRequestService } from "../services/http/githubRequest.service";
|
||||||
|
|
||||||
export const githubRequestController = async (ctx: Context) => {
|
export const githubRequestController = async (
|
||||||
const loginUrl = await githubRequestService();
|
ctx: Context & { query: { callback?: string } }
|
||||||
|
) => {
|
||||||
|
const loginUrl = await githubRequestService(ctx.query.callback);
|
||||||
return returnReadResponse(
|
return returnReadResponse(
|
||||||
ctx.set,
|
ctx.set,
|
||||||
200,
|
200,
|
||||||
"Login URL generated successfully",
|
"Login URL generated successfully",
|
||||||
String(loginUrl)
|
loginUrl
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
import { GitHub } from "arctic";
|
import { GitHub } from "arctic";
|
||||||
|
|
||||||
export const githubProvider = () => {
|
export const githubProvider = (
|
||||||
const redirectURI = `${process.env.APP_PROTOCOL}://${process.env.APP_DOMAIN}${process.env.GITHUB_CLIENT_CALLBACK}`;
|
callbackURI = `${process.env.APP_PROTOCOL}://${process.env.APP_DOMAIN}${process.env.GITHUB_DEFAULT_CALLBACK}`
|
||||||
|
) => {
|
||||||
return new GitHub(
|
return new GitHub(
|
||||||
process.env.GITHUB_CLIENT_ID!,
|
process.env.GITHUB_CLIENT_ID!,
|
||||||
process.env.GITHUB_CLIENT_SECRET!,
|
process.env.GITHUB_CLIENT_SECRET!,
|
||||||
redirectURI
|
callbackURI
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -2,9 +2,9 @@ import * as arctic from "arctic";
|
|||||||
import { githubProvider } from "../../providers/github.provider";
|
import { githubProvider } from "../../providers/github.provider";
|
||||||
import { AppError } from "../../../../helpers/error/instances/app";
|
import { AppError } from "../../../../helpers/error/instances/app";
|
||||||
|
|
||||||
export const githubRequestService = async () => {
|
export const githubRequestService = async (callbackURI?: string) => {
|
||||||
try {
|
try {
|
||||||
const github = githubProvider();
|
const github = githubProvider(callbackURI);
|
||||||
const state = arctic.generateState();
|
const state = arctic.generateState();
|
||||||
const scopes = ["user:email"];
|
const scopes = ["user:email"];
|
||||||
const url = github.createAuthorizationURL(state, scopes);
|
const url = github.createAuthorizationURL(state, scopes);
|
||||||
|
|||||||
Reference in New Issue
Block a user