@blinkk/editor
Version:
Structured content editor with live previews.
54 lines • 2.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GithubApi = void 0;
const api_1 = require("../api");
const dataStorage_1 = require("../../utility/dataStorage");
const uuid_1 = require("@blinkk/selective-edit/dist/src/utility/uuid");
const CLIENT_ID = 'Iv1.e422a5bfa1197db1';
const sessionStorage = new dataStorage_1.SessionDataStorage();
/**
* Example api that returns data through a 'simulated' network.
*/
class GithubApi extends api_1.ServiceServerApi {
/**
* Verify that the authentication for services that require auth.
*
* @returns True if the auth checks out.
*/
checkAuth() {
let githubState = sessionStorage.getItem('github.state');
if (!githubState) {
githubState = uuid_1.generateUUID();
sessionStorage.setItem('github.state', githubState);
}
const githubCode = sessionStorage.getItem('github.code');
if (!githubCode) {
// Save the current url to redirect back to after auth.
sessionStorage.setItem('redirectUrl', window.location.href);
const loginUrl = new URL('/login/oauth/authorize', 'https://github.com');
const loginParams = new URLSearchParams();
loginParams.set('client_id', CLIENT_ID);
loginParams.set('redirect_uri', `${window.location.origin}/gh/callback/`);
loginParams.set('state', githubState);
loginUrl.search = loginParams.toString();
console.log('login URL: ', loginUrl.toString());
window.location.href = loginUrl.toString();
return false;
}
return true;
}
/**
* Specific services may need to add additional params to all of
* the api request (such as authentication params.)
*
* @param params Params being sent to the api.
* @returns Updated params to send to the api.
*/
expandParams(params) {
params['githubState'] = sessionStorage.getItem('github.state');
params['githubCode'] = sessionStorage.getItem('github.code');
return params;
}
}
exports.GithubApi = GithubApi;
//# sourceMappingURL=githubApi.js.map