Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds dev flag for new private key #55

Merged
merged 4 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/services/discordBotServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ export const updateUserRoles = async (env: env, payload: DiscordUserRole[]): Pro
try {
const url = config(env).DISCORD_BOT_API_URL;
const token = await generateDiscordBotJwt(env);

const response = await env.DISCORD_BOT.fetch(`${url}/roles?action=add-role`, {
//TODO(@Ajeyakrishna-k): remove dev flag https://github.com/Real-Dev-Squad/discord-slash-commands/issues/193
const devQuery = env.FF_CRON_DISCORD_KEY_PAIR_FLOW === 'true' ? '&dev=true' : '';
const response = await env.DISCORD_BOT.fetch(`${url}/roles?action=add-role${devQuery}`, {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
Expand Down
4 changes: 3 additions & 1 deletion src/utils/generateJwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ export const generateJwt = async (env: env) => {

export const generateDiscordBotJwt = async (env: env) => {
try {
//TODO(@Ajeyakrishna-k): remove dev flag https://github.com/Real-Dev-Squad/discord-slash-commands/issues/193
const privateKey = env.FF_CRON_DISCORD_KEY_PAIR_FLOW === 'true' ? env.DISCORD_SERVICE_PRIVATE_KEY : env.DISCORD_BOT_PRIVATE_KEY;
const authToken = await jwt.sign(
{
exp: Math.floor(Date.now() / 1000) + 60,
},
env.DISCORD_BOT_PRIVATE_KEY,
privateKey,
{ algorithm: 'RS256' },
);
return authToken;
Expand Down
Loading