Skip to content

Instantly share code, notes, and snippets.

@dam1r89
Last active December 12, 2023 08:39
Show Gist options
  • Save dam1r89/62f530b52bff1e9c3090aa5b6ec9ac4f to your computer and use it in GitHub Desktop.
Save dam1r89/62f530b52bff1e9c3090aa5b6ec9ac4f to your computer and use it in GitHub Desktop.
const express = require("express");
const querystring = require("querystring");
const session = require("express-session");
const app = express();
const port = 8080;
const url = `http://localhost:${port}`;
const oauthServer = "https://app.startinfinity.com";
const appId = "<paste-app-id>";
const appSecret = "<paste-app-scret>";
const callbackUrl = `${url}/callback`;
app.use(session({ secret: "keyboard cat", cookie: { maxAge: 60000 } }));
app.get("/redirect", (req, res) => {
const state = "<generate-random-string-token>";
req.session.state = state;
const query = querystring.stringify({
client_id: appId,
redirect_uri: callbackUrl,
response_type: "code",
scope: "",
state: state,
});
res.redirect(`${oauthServer}/oauth/authorize?${query}`);
});
app.get("/callback", async (req, res) => {
if (req.session.state !== req.query.state) {
throw Error("States do not match");
}
const data = {
grant_type: "authorization_code",
client_id: appId,
client_secret: appSecret,
redirect_uri: callbackUrl,
code: req.query.code,
};
const response = await fetch(`${oauthServer}/oauth/token`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
redirect: "follow",
body: JSON.stringify(data),
});
const token = await response.json();
res.json(token);
});
app.listen(port, () => {
console.log(`Example app listening at ${url}`);
});
@raftx24
Copy link

raftx24 commented May 16, 2022


  const response = await fetch('https://app.startinfinity.com/oauth/token/refresh', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    redirect: 'follow',
    body: JSON.stringify({
       refresh_token: token.refresh_token
    }),
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment