[bug] HTTP 400 on POST /api/v7/oauth2/token
See original GitHub issueOAuth URL directs to /oauth/get_token no problem with code, gives 400 on redirecting to /oauth/callback
environment variables:
OAUTH_CLIENT_ID=1234
OAUTH_CLIENT_SECRET=5678
OAUTH_REDIRECT_HOST=http://localhost:3001
my code:
process.env.NODE_ENV = process.env.NODE_ENV || "development";
require("dotenv-cra").config({
path: __dirname + "/.env"
});
const express = require("express");
const cors = require("cors");
const DiscordOauth2 = require("discord-oauth2");
const oauth = new DiscordOauth2();
const app = express();
app.use(cors());
app.use("/oauth/get_token", async (req, res) => {
const token = await oauth.tokenRequest({
clientId: process.env.OAUTH_CLIENT_ID,
clientSecret: process.env.OAUTH_CLIENT_SECRET,
code: req.query.code,
scope: "identify guilds",
grantType: "authorization_code",
redirectUri: process.env.OAUTH_REDIRECT_HOST + "/callback",
});
console.log(token);
});
app.use("/oauth/callback", async (req, res) => {
console.log(req.headers);
console.log(req.query);
console.log(req.body);
res.send("thanks");
});
const PORT = process.env.PORT || "3001";
app.listen(PORT, e => {
if (e) throw e;
console.log("Listening at port " + PORT);
});
Issue Analytics
- State:
- Created 3 years ago
- Comments:9
Top Results From Across the Web
400 Bad Request on POST /api/v7/oauth2/token #16 - GitHub
It does appear that it is due to Discord fixing a bug based on the discussions in the Discord API guild. 4
Read more >400 Error when requesting a token from Discord API
After further research, I discovered the following video which helped me out. Here is the working code:
Read more >Why do I get Error code 400 "bad Request" when posting ...
Why do I get Error code 400 "bad Request" when posting HTTP request to token endpoint to exchange for an Oauth2 access token...
Read more >Bad request 400 when trying to retrieve the Access Token
Hi guys, I'm trying to use the authentication process, but when I make the POST to the app to retrieve the Access Token...
Read more >Fixes, Limitations, and Known Issues - ForgeRock Backstage
OPENAM-16703: OAuth2 Access token obtained from refresh token is certificate-bound regardless of "Certificate-Bound Access Tokens" configuration (when ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m an idiot, never mind
you should open a new ticket instead of commenting here. this ticket is closed.