let url = `https://authentication-url.example.com/api/github/oauth/login`;
this.authWindow = window.open(
url,
'Authorization',
`width=500, height=500, top=300, left=300`
);
this.authWindow.focus();
This flow, redirects me from login, to https://github.com/login/oauth/authorize
which redirects me to /api/github/oauth/callback with the code as a query string param
The response from this is a html page which contains a token. But how can I access this token programatically. Ie, should I not use createNodeMiddleware and return a custom javascript which sends a message to window.postMessage which I can listen for in my single page application.
import {createNodeMiddleware, OAuthApp} from "@octokit/oauth-app";
const octokitApp = new OAuthApp({
clientType: "github-app",
// appId: APP_ID,
// privateKey: PRIVATE_KEY,
clientId: CLIENT_ID,
clientSecret: CLIENT_SECRET,
});
octokitApp.on("token", async ({octokit}) => {
const {data} = await octokit.request("GET /user");
console.log(`Token retrieved for ${data.login}`);
});
const authApp = express();
authApp.use(createNodeMiddleware(octokitApp));
export authApp
Is how the express routes look.