From 6f5145582c58a2ffce4f92c6b2d4de8734ad51bc Mon Sep 17 00:00:00 2001 From: Anil Vishnoi Date: Wed, 2 Oct 2024 00:27:29 -0700 Subject: [PATCH] Add environemnt variable to set the authentication org This org will be used to authenticate user. Signed-off-by: Anil Vishnoi --- .env.example | 14 +++++++++----- src/app/api/auth/[...nextauth]/route.ts | 10 +++++----- src/app/api/pr/knowledge/route.ts | 2 +- src/app/api/pr/skill/route.ts | 3 +-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.env.example b/.env.example index 9abe7573..fb4e23cd 100644 --- a/.env.example +++ b/.env.example @@ -1,16 +1,20 @@ IL_UI_ADMIN_USERNAME=admin IL_UI_ADMIN_PASSWORD=password + OAUTH_GITHUB_ID= OAUTH_GITHUB_SECRET= -GITHUB_TOKEN= + NEXTAUTH_SECRET=your_super_secret_random_string NEXTAUTH_URL=http://localhost:3000 -TAXONOMY_DOCUMENTS_REPO=github.com// -NEXT_PUBLIC_TAXONOMY_REPO_OWNER= -NEXT_PUBLIC_TAXONOMY_REPO= - IL_GRANITE_API= IL_GRANITE_MODEL_NAME= IL_MERLINITE_API= IL_MERLINITE_MODEL_NAME= +IL_UI_DEPLOYMENT=dev ## Comment it out if it's not a dev deployment + +GITHUB_TOKEN= +TAXONOMY_DOCUMENTS_REPO=github.com/instructlab-public/taxonomy-knowledge-docs +NEXT_PUBLIC_AUTHENTICATION_ORG= +NEXT_PUBLIC_TAXONOMY_REPO_OWNER= +NEXT_PUBLIC_TAXONOMY_REPO= diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts index 5acf0846..62a4dead 100644 --- a/src/app/api/auth/[...nextauth]/route.ts +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -37,7 +37,7 @@ const logger = winston.createLogger({ transports: [new winston.transports.Console(), new winston.transports.File({ filename: path.join(process.cwd(), 'auth.log') })] }); -const ORG = process.env.NEXT_PUBLIC_TAXONOMY_REPO_OWNER!; +const ORG = process.env.NEXT_PUBLIC_AUTHENTICATION_ORG!; const authOptions: NextAuthOptions = { providers: [ @@ -107,16 +107,16 @@ const authOptions: NextAuthOptions = { }); if (response.status === 204) { - console.log(`User ${githubProfile.login} logged in successfully with GitHub`); - logger.info(`User ${githubProfile.login} logged in successfully with GitHub`); + console.log(`User ${githubProfile.login} successfully authenticated with GitHub organization - ${ORG}`); + logger.info(`User ${githubProfile.login} successfully authenticated with GitHub organization - ${ORG}`); return true; } else if (response.status === 404) { console.log(`User ${githubProfile.login} is not a member of the ${ORG} organization`); logger.warn(`User ${githubProfile.login} is not a member of the ${ORG} organization`); return `/error?error=AccessDenied`; // Redirect to custom error page } else { - console.log(`Unexpected error for user ${githubProfile.login} during organization membership verification`); - logger.error(`Unexpected error for user ${githubProfile.login} during organization membership verification`); + console.log(`Unexpected error while authenticating user ${githubProfile.login} with ${ORG} github organization.`); + logger.error(`Unexpected error while authenticating user ${githubProfile.login} with ${ORG} github organization.`); return false; } } catch (error) { diff --git a/src/app/api/pr/knowledge/route.ts b/src/app/api/pr/knowledge/route.ts index 2929d9d7..9207a5f4 100644 --- a/src/app/api/pr/knowledge/route.ts +++ b/src/app/api/pr/knowledge/route.ts @@ -37,7 +37,7 @@ export async function POST(req: NextRequest) { // Fetch GitHub username const githubUsername = await getGitHubUsername(headers); - console.log('GitHub Username:', githubUsername); + console.log('Knowledge contribution from gitHub Username:', githubUsername); // Check if user's fork exists, if not, create it const forkExists = await checkUserForkExists(headers, githubUsername, UPSTREAM_REPO_NAME); diff --git a/src/app/api/pr/skill/route.ts b/src/app/api/pr/skill/route.ts index 201499f3..a641650e 100644 --- a/src/app/api/pr/skill/route.ts +++ b/src/app/api/pr/skill/route.ts @@ -14,7 +14,6 @@ const UPSTREAM_REPO_NAME = process.env.NEXT_PUBLIC_TAXONOMY_REPO!; export async function POST(req: NextRequest) { const token = await getToken({ req, secret: process.env.NEXTAUTH_SECRET! }); - console.log('GitHub Token:', token); if (!token || !token.accessToken) { console.error('Unauthorized: Missing or invalid access token'); @@ -34,7 +33,7 @@ export async function POST(req: NextRequest) { const { content, attribution, name, email, submissionSummary, documentOutline, filePath } = body; const githubUsername = await getGitHubUsername(headers); - console.log('GitHub Username:', githubUsername); + console.log('Skill contribution from gitHub Username:', githubUsername); // Check if user's fork exists, if not, create it const forkExists = await checkUserForkExists(headers, githubUsername, UPSTREAM_REPO_NAME);