Skip to content

Commit

Permalink
Merge pull request #229 from vishnoianil/cp-pr-227
Browse files Browse the repository at this point in the history
Add environment variable to set the authentication org
  • Loading branch information
Gregory-Pereira authored Oct 2, 2024
2 parents 659c6f0 + 6f51455 commit 1dfd90a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
14 changes: 9 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
IL_UI_ADMIN_USERNAME=admin
IL_UI_ADMIN_PASSWORD=password

OAUTH_GITHUB_ID=<OAUTH_APP_ID>
OAUTH_GITHUB_SECRET=<OAUTH_APP_SECRET>
GITHUB_TOKEN=<TOKEN FOR OAUTH INSTRUCTLAB MEMBER LOOKUP>

NEXTAUTH_SECRET=your_super_secret_random_string
NEXTAUTH_URL=http://localhost:3000

TAXONOMY_DOCUMENTS_REPO=github.com/<USER_ID>/<REPO_NAME>
NEXT_PUBLIC_TAXONOMY_REPO_OWNER=<GITHUB_ACCOUNT>
NEXT_PUBLIC_TAXONOMY_REPO=<REPO_NAME>

IL_GRANITE_API=<GRANITE_HOST>
IL_GRANITE_MODEL_NAME=<GRANITE_MODEL_NAME>
IL_MERLINITE_API=<MERLINITE_HOST>
IL_MERLINITE_MODEL_NAME=<MERLINITE_MODEL_NAME>
IL_UI_DEPLOYMENT=dev ## Comment it out if it's not a dev deployment

GITHUB_TOKEN=<TOKEN FOR OAUTH INSTRUCTLAB MEMBER LOOKUP>
TAXONOMY_DOCUMENTS_REPO=github.com/instructlab-public/taxonomy-knowledge-docs
NEXT_PUBLIC_AUTHENTICATION_ORG=<AUTHENTICATION_ORG>
NEXT_PUBLIC_TAXONOMY_REPO_OWNER=<GITHUB_ACCOUNT>
NEXT_PUBLIC_TAXONOMY_REPO=<REPO_NAME>
10 changes: 5 additions & 5 deletions src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/pr/knowledge/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/app/api/pr/skill/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
Expand Down

0 comments on commit 1dfd90a

Please sign in to comment.