Safer Basic Auth

This commit is contained in:
Daniel Odendahl Jr
2018-02-26 23:19:42 +00:00
parent 53eb402472
commit 59a5c873c2
4 changed files with 9 additions and 7 deletions
+2 -1
View File
@@ -33,7 +33,8 @@ module.exports = class GitHubCommand extends Command {
async run(msg, { author, repository }) {
try {
const { body } = await snekfetch
.get(`https://${GITHUB_USERNAME}:${GITHUB_PASSWORD}@api.github.com/repos/${author}/${repository}`);
.get(`https://api.github.com/repos/${author}/${repository}`)
.set({ Authorization: `Basic ${Buffer.from(`${GITHUB_USERNAME}:${GITHUB_PASSWORD}`).toString('base64')}` });
const embed = new MessageEmbed()
.setColor(0xFFFFFF)
.setAuthor('GitHub', 'https://i.imgur.com/e4HunUm.png', 'https://github.com/')
+3 -2
View File
@@ -29,8 +29,9 @@ module.exports = class MyAnimeListAnimeCommand extends Command {
async run(msg, { query }) {
try {
const { text } = await snekfetch
.get(`https://${MAL_USERNAME}:${MAL_PASSWORD}@myanimelist.net/api/anime/search.xml`)
.query({ q: query });
.get('https://myanimelist.net/api/anime/search.xml')
.query({ q: query })
.set({ Authorization: `Basic ${Buffer.from(`${MAL_USERNAME}:${MAL_PASSWORD}`).toString('base64')}` });
const body = await xml(text);
const data = body.anime.entry[0];
const embed = new MessageEmbed()
+3 -2
View File
@@ -29,8 +29,9 @@ module.exports = class MyAnimeListMangaCommand extends Command {
async run(msg, { query }) {
try {
const { text } = await snekfetch
.get(`https://${MAL_USERNAME}:${MAL_PASSWORD}@myanimelist.net/api/manga/search.xml`)
.query({ q: query });
.get('https://myanimelist.net/api/manga/search.xml')
.query({ q: query })
.set({ Authorization: `Basic ${Buffer.from(`${MAL_USERNAME}:${MAL_PASSWORD}`).toString('base64')}` });
const body = await xml(text);
const data = body.manga.entry[0];
const embed = new MessageEmbed()
+1 -2
View File
@@ -61,11 +61,10 @@ module.exports = class TwitterCommand extends Command {
}
async fetchToken() {
const auth = Buffer.from(`${TWITTER_KEY}:${TWITTER_SECRET}`).toString('base64');
const { body } = await snekfetch
.post('https://api.twitter.com/oauth2/token')
.set({
Authorization: `Basic ${auth}`,
Authorization: `Basic ${Buffer.from(`${TWITTER_KEY}:${TWITTER_SECRET}`).toString('base64')}`,
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8'
})
.send('grant_type=client_credentials');