👔 (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:
@ -2,12 +2,14 @@ import { Context } from "elysia";
|
||||
import { returnReadResponse } from "../../../helpers/callback/httpResponse";
|
||||
import { githubRequestService } from "../services/http/githubRequest.service";
|
||||
|
||||
export const githubRequestController = async (ctx: Context) => {
|
||||
const loginUrl = await githubRequestService();
|
||||
export const githubRequestController = async (
|
||||
ctx: Context & { query: { callback?: string } }
|
||||
) => {
|
||||
const loginUrl = await githubRequestService(ctx.query.callback);
|
||||
return returnReadResponse(
|
||||
ctx.set,
|
||||
200,
|
||||
"Login URL generated successfully",
|
||||
String(loginUrl)
|
||||
loginUrl
|
||||
);
|
||||
};
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
import { GitHub } from "arctic";
|
||||
|
||||
export const githubProvider = () => {
|
||||
const redirectURI = `${process.env.APP_PROTOCOL}://${process.env.APP_DOMAIN}${process.env.GITHUB_CLIENT_CALLBACK}`;
|
||||
export const githubProvider = (
|
||||
callbackURI = `${process.env.APP_PROTOCOL}://${process.env.APP_DOMAIN}${process.env.GITHUB_DEFAULT_CALLBACK}`
|
||||
) => {
|
||||
return new GitHub(
|
||||
process.env.GITHUB_CLIENT_ID!,
|
||||
process.env.GITHUB_CLIENT_SECRET!,
|
||||
redirectURI
|
||||
callbackURI
|
||||
);
|
||||
};
|
||||
|
||||
@ -2,9 +2,9 @@ import * as arctic from "arctic";
|
||||
import { githubProvider } from "../../providers/github.provider";
|
||||
import { AppError } from "../../../../helpers/error/instances/app";
|
||||
|
||||
export const githubRequestService = async () => {
|
||||
export const githubRequestService = async (callbackURI?: string) => {
|
||||
try {
|
||||
const github = githubProvider();
|
||||
const github = githubProvider(callbackURI);
|
||||
const state = arctic.generateState();
|
||||
const scopes = ["user:email"];
|
||||
const url = github.createAuthorizationURL(state, scopes);
|
||||
|
||||
Reference in New Issue
Block a user