👔 (oauth) add callback URI option for google
Adding a callback option to the Google OAuth provider used to define the OAuth callback URI. If not defined, the callback URI will use the default value in the .env file.
This commit is contained in:
@ -3,9 +3,11 @@ import { mainErrorHandler } from "../../../helpers/error/handler";
|
||||
import { googleRequestService } from "../services/http/googleRequest.service";
|
||||
import { returnReadResponse } from "../../../helpers/callback/httpResponse";
|
||||
|
||||
export const googleRequestController = async (ctx: Context) => {
|
||||
export const googleRequestController = async (
|
||||
ctx: Context & { query: { callback?: string } }
|
||||
) => {
|
||||
try {
|
||||
const loginUrl = await googleRequestService();
|
||||
const loginUrl = await googleRequestService(ctx.query.callback);
|
||||
return returnReadResponse(
|
||||
ctx.set,
|
||||
200,
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
import { Google } from "arctic";
|
||||
|
||||
export const googleProvider = () => {
|
||||
const redirectURI = `${process.env.APP_PROTOCOL}://${process.env.APP_DOMAIN}${process.env.GOOGLE_CLIENT_CALLBACK}`;
|
||||
export const googleProvider = (
|
||||
callbackURI = `${process.env.APP_PROTOCOL}://${process.env.APP_DOMAIN}${process.env.GOOGLE_DEFAULT_CALLBACK}`
|
||||
) => {
|
||||
return new Google(
|
||||
process.env.GOOGLE_CLIENT_ID!,
|
||||
process.env.GOOGLE_CLIENT_SECRET!,
|
||||
redirectURI
|
||||
callbackURI
|
||||
);
|
||||
};
|
||||
|
||||
@ -3,9 +3,9 @@ import { AppError } from "../../../../helpers/error/instances/app";
|
||||
import { googleProvider } from "../../providers/google.provider";
|
||||
import { redis } from "../../../../utils/databases/redis/connection";
|
||||
|
||||
export const googleRequestService = async () => {
|
||||
export const googleRequestService = async (callbackURI?: string) => {
|
||||
try {
|
||||
const google = googleProvider();
|
||||
const google = googleProvider(callbackURI);
|
||||
const state = arctic.generateState();
|
||||
const codeVerifier = arctic.generateCodeVerifier();
|
||||
const scopes = ["openid", "profile", "email"];
|
||||
|
||||
Reference in New Issue
Block a user