Skip to content
This repository has been archived by the owner on Feb 10, 2021. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
voldikss committed Jan 8, 2021
1 parent f13965b commit dd7f5e3
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions src/service/github.oauth.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { window, workspace } from "coc.nvim";
import { window, workspace } from "coc.nvim"
import fetch from 'node-fetch'
import express from 'express'
import { Server } from "http";
import GistConfig from "../util/gistcfg";
import { URLSearchParams } from "url";
import { Server } from "http"
import GistConfig from "../util/gistcfg"
import { URLSearchParams } from "url"

export class GitHubOAuthService {
private app: express.Express;
private server: Server;
private app: express.Express
private server: Server
private clientId = 'b32302cd17c89e5d8fcd'
private clientSecret = 'f40b66f0851e9ce94b4ba643b64583fadbc103db'
constructor(private gistcfg: GistConfig) {
this.app = express();
this.app.use(express.json(), express.urlencoded({ extended: false }));
this.app = express()
this.app.use(express.json(), express.urlencoded({ extended: false }))
}

public async start(): Promise<void> {
Expand All @@ -26,21 +26,21 @@ export class GitHubOAuthService {
this.app.get('/oauth-callback', async (req, res) => {
const params = new URLSearchParams(
await (await this.getToken(req.query.code)).text()
);
)
res.send(`
<html lang="en">
<body>
<h1>Success! You may now close this tab.</h1>
<style>
html, body {
background-color: #1a1a1a;
color: #c3c3c3;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
margin: 0;
background-color: #1a1a1a
color: #c3c3c3
display: flex
justify-content: center
align-items: center
height: 100%
width: 100%
margin: 0
}
</style>
</body>
Expand All @@ -54,15 +54,15 @@ export class GitHubOAuthService {
}

private getToken(code: string) {
const params = new URLSearchParams();
params.append("client_id", this.clientId);
params.append("client_secret", this.clientSecret);
params.append("code", code);
const params = new URLSearchParams()
params.append("client_id", this.clientId)
params.append("client_secret", this.clientSecret)
params.append("code", code)
const promise = fetch(`https://github.com/login/oauth/access_token`, {
method: "POST",
body: params
});
return promise;
})
return promise
}

public async saveToken(token: string): Promise<void> {
Expand Down

0 comments on commit dd7f5e3

Please sign in to comment.