ESI SSO POST request error JS

Hi there,
I think I’m to dumb to see the error here. I’m at point 5 of OAuth 2.0 for Web Based Applications | esi-docs
and need to make a POST request, but I always receive the following error:

error: ‘invalid_grant’,
error_description: ‘Grant type is not supported.’

although the documentation clearly tells me to set it to “authorization_code”.

The query.code is provided by calling https://login.eveonline.com/v2/oauth/authorize/, so it is a v2 code.

Maybe someone of you can see what I’m doing wrong here.

Thank you very much.

I replaced all credentials of the application with ||||||||||| to censor them, but in my code, they are working (I changed them and got back other errors)

const app = express();
const port = process.env.PORT || 8000;

app.use(express.json());
app.use(cors({
    origin: "*"
}));


app.get("/", async(req, res, next) => {
    const query = req.query;
    const auth = "|||||||||||||||||||||| : |||||||||||||||||||||||||||"
    console.log(query)
    const header = {
        "Authorization": "Basic |||||||||||||||||||||||",
        "Content-Type": "application/x-www-form-urlencoded",
        "Host": "login.eveonline.com"
    }


    try{
        const {data} = await axios.post(`https://login.eveonline.com/v2/oauth/token`,
        {
            grant_type: "authorization_code"
        }, 
        {
            headers: header
        }
        )
        console.log(data);
    }catch(err){
        //console.log(err)
    }

    next()
})

const wss = new WebSocket.Server({ port: 8080 },()=>{
    console.log('websocket server running')
})


wss.on('connection', function connection(ws) {
    const id = uuid();
    ws.id = id
    ws.send(`id;${id}`)
    //ws.on('message', (data) => {
    //    ws.send(`id;${id}`)
    //})
 })

 app.listen(port, () => {
     console.log("express server running")
 })

Two things things to double check:

  1. You need to make the POST with form encoded data as the body, not JSON
  2. You also need to include the code within the body, which it doesn’t look like you are

Another thing you can try is make the request via Postman or curl to validate things are working. Then you would know it’s a code issue.

I did made them via Postman and got the same error. I can try points 1 and 2. Thanks for your answer.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.