UNPKG

@fgnass/decap-cms-backend-aws-cognito-github-proxy

Version:

GitHub backend for Decap CMS proxied through AWS Cognito

46 lines 1.73 kB
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } import * as React from 'react'; import { GitHubBackend } from 'decap-cms-backend-github'; import AuthenticationPage from './AuthenticationPage'; import { jsx as ___EmotionJSX } from "@emotion/react"; export default class AwsCognitoGitHubProxyBackend extends GitHubBackend { constructor(config, options = {}) { super(config, options); this.bypassWriteAccessCheckForAppTokens = true; this.tokenKeyword = 'Bearer'; } authComponent() { const wrappedAuthenticationPage = props => ___EmotionJSX(AuthenticationPage, _extends({}, props, { backend: this })); wrappedAuthenticationPage.displayName = 'AuthenticationPage'; return wrappedAuthenticationPage; } async currentUser({ token }) { if (!this._currentUserPromise) { this._currentUserPromise = fetch(this.baseUrl + '/oauth2/userInfo', { headers: { Authorization: `${this.tokenKeyword} ${token}` } }).then(async res => { if (res.status == 401) { this.logout(); return Promise.reject('Token expired'); } const userInfo = await res.json(); const owner = this.originRepo.split('/')[1]; return { name: userInfo.email, login: owner, avatar_url: `https://github.com/${owner}.png` }; }); } return this._currentUserPromise; } async getPullRequestAuthor(pullRequest) { return pullRequest.user?.login; } }