0.1.8 • Published 2 years ago

simple-discord-auth v0.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

simple-discord-auth

Simple Discord Authorization for verifying validity of requests coming from Discord's HTTP Interactions endpoint.

Example Usage: Please note, this example is taken from a discord bot that receives Discord Payloads via a lambda function url

import { verifyDiscordRequest } from "simple-discord-auth";

const BOT_PUBLIC_KEY = process.env.PUBLIC_KEY
const BadRequest = {
  statusCode: 401,
  body: "Bad Request",
};

const InternalError = {
  statusCode: 500,
  body: "Internal Server Error"
}

export const handler = async (_evt) => {
  if(!BOT_PUBLIC_KEY) return InternalError
  const {body, headers} = _evt;
  if(!body) return BadRequest;

  // verify request is legitimate
  const isVerified = verifyDiscordRequest(body, headers, BOT_PUBLIC_KEY);

  if(!isVerified) return BadRequest;
  // ... Rest of code to handle commands below
}
0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago