0.1.8 • Published 3 years ago

simple-discord-auth v0.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
3 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

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago