add-cms
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
# Change Log
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [3.4.1](https://github.com/decaporg/decap-cms/compare/decap-cms-backend-aws-cognito-github-proxy@3.4.0...decap-cms-backend-aws-cognito-github-proxy@3.4.1) (2025-07-31)
|
||||
|
||||
**Note:** Version bump only for package decap-cms-backend-aws-cognito-github-proxy
|
||||
|
||||
# [3.4.0](https://github.com/decaporg/decap-cms/compare/decap-cms-backend-aws-cognito-github-proxy@3.2.2...decap-cms-backend-aws-cognito-github-proxy@3.4.0) (2025-07-15)
|
||||
|
||||
### Features
|
||||
|
||||
- add logo to header ([#7487](https://github.com/decaporg/decap-cms/issues/7487)) ([b540ace](https://github.com/decaporg/decap-cms/commit/b540acec943eb231df6aac7b1d515d9b4b84fa5d))
|
||||
|
||||
# [3.3.0](https://github.com/decaporg/decap-cms/compare/decap-cms-backend-aws-cognito-github-proxy@3.2.2...decap-cms-backend-aws-cognito-github-proxy@3.3.0) (2025-06-26)
|
||||
|
||||
**Note:** Version bump only for package decap-cms-backend-aws-cognito-github-proxy
|
||||
|
||||
## [3.2.2](https://github.com/decaporg/decap-cms/compare/decap-cms-backend-aws-cognito-github-proxy@3.2.1...decap-cms-backend-aws-cognito-github-proxy@3.2.2) (2024-08-13)
|
||||
|
||||
### Reverts
|
||||
|
||||
- Revert "Update dependencies (#7264)" ([22d483a](https://github.com/decaporg/decap-cms/commit/22d483a5b0c654071ae05735ac4f49abdc13d38c)), closes [#7264](https://github.com/decaporg/decap-cms/issues/7264)
|
||||
|
||||
## [3.2.1](https://github.com/decaporg/decap-cms/compare/decap-cms-backend-aws-cognito-github-proxy@3.2.0...decap-cms-backend-aws-cognito-github-proxy@3.2.1) (2024-08-13)
|
||||
|
||||
**Note:** Version bump only for package decap-cms-backend-aws-cognito-github-proxy
|
||||
|
||||
# [3.2.0](https://github.com/decaporg/decap-cms/compare/decap-cms-backend-aws-cognito-github-proxy@3.1.2...decap-cms-backend-aws-cognito-github-proxy@3.2.0) (2024-08-07)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- fetch GitHub PR author name, fixes [#7232](https://github.com/decaporg/decap-cms/issues/7232) ([#7253](https://github.com/decaporg/decap-cms/issues/7253)) ([0e5335d](https://github.com/decaporg/decap-cms/commit/0e5335daba1b67816b4a0c24d1a2d9a185e3b54f))
|
||||
|
||||
## [3.1.2](https://github.com/decaporg/decap-cms/compare/decap-cms-backend-aws-cognito-github-proxy@3.1.1...decap-cms-backend-aws-cognito-github-proxy@3.1.2) (2024-03-21)
|
||||
|
||||
**Note:** Version bump only for package decap-cms-backend-aws-cognito-github-proxy
|
||||
|
||||
## [3.1.1](https://github.com/decaporg/decap-cms/compare/decap-cms-backend-aws-cognito-github-proxy@3.1.0...decap-cms-backend-aws-cognito-github-proxy@3.1.1) (2024-02-21)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- gitlab pkce auth error ([#7110](https://github.com/decaporg/decap-cms/issues/7110)) ([bcd58d6](https://github.com/decaporg/decap-cms/commit/bcd58d6e117b4654b3e0dca173f7f8aaca8dabdf))
|
||||
|
||||
# [3.1.0](https://github.com/decaporg/decap-cms/compare/decap-cms-backend-aws-cognito-github-proxy@3.1.0-beta.2...decap-cms-backend-aws-cognito-github-proxy@3.1.0) (2024-02-01)
|
||||
|
||||
**Note:** Version bump only for package decap-cms-backend-aws-cognito-github-proxy
|
||||
|
||||
# 3.1.0-beta.2 (2024-01-31)
|
||||
|
||||
**Note:** Version bump only for package decap-cms-backend-aws-cognito-github-proxy
|
||||
@@ -0,0 +1,9 @@
|
||||
# GitHub backend
|
||||
|
||||
An abstraction layer between the CMS and a proxied version of [Github](https://docs.github.com/en/rest).
|
||||
|
||||
## Code structure
|
||||
|
||||
`Implementation` - wraps [Github Backend](https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-lib-auth/README.md) for proxied version of Github.
|
||||
|
||||
`AuthenticationPage` - uses [lib-auth](https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-lib-auth/README.md) to create an AWS Cognito compatible generic Authentication page supporting PKCE.
|
||||
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "decap-cms-backend-aws-cognito-github-proxy",
|
||||
"description": "GitHub backend for Decap CMS proxied through AWS Cognito",
|
||||
"version": "3.4.1",
|
||||
"license": "MIT",
|
||||
"repository": "https://github.com/decaporg/decap-cms/tree/main/packages/decap-cms-backend-aws-cognito-github-proxy",
|
||||
"bugs": "https://github.com/decaporg/decap-cms/issues",
|
||||
"module": "dist/esm/index.js",
|
||||
"main": "dist/decap-cms-backend-aws-cognito-github-proxy.js",
|
||||
"keywords": [
|
||||
"decap-cms",
|
||||
"backend",
|
||||
"github",
|
||||
"aws-cognito"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"scripts": {
|
||||
"develop": "npm run build:esm -- --watch",
|
||||
"build": "cross-env NODE_ENV=production webpack",
|
||||
"build:esm": "cross-env NODE_ENV=esm babel src --out-dir dist/esm --ignore **/__tests__ --root-mode upward --extensions \".js,.jsx,.ts,.tsx\""
|
||||
},
|
||||
"dependencies": {
|
||||
"apollo-cache-inmemory": "^1.6.2",
|
||||
"apollo-client": "^2.6.3",
|
||||
"apollo-link-context": "^1.0.18",
|
||||
"apollo-link-http": "^1.5.15",
|
||||
"common-tags": "^1.8.0",
|
||||
"graphql": "^15.0.0",
|
||||
"graphql-tag": "^2.10.1",
|
||||
"js-base64": "^3.0.0",
|
||||
"semaphore": "^1.1.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@emotion/react": "^11.11.1",
|
||||
"@emotion/styled": "^11.11.0",
|
||||
"decap-cms-backend-github": "^3.0.0",
|
||||
"decap-cms-lib-auth": "^3.0.0",
|
||||
"decap-cms-lib-util": "^3.0.0",
|
||||
"decap-cms-ui-auth": "^3.0.0",
|
||||
"decap-cms-ui-default": "^3.0.0",
|
||||
"lodash": "^4.17.11",
|
||||
"prop-types": "^15.7.2",
|
||||
"react": "^19.1.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import styled from '@emotion/styled';
|
||||
import { PkceAuthenticator } from 'decap-cms-lib-auth';
|
||||
import { AuthenticationPage, Icon } from 'decap-cms-ui-default';
|
||||
|
||||
const LoginButtonIcon = styled(Icon)`
|
||||
margin-right: 18px;
|
||||
`;
|
||||
|
||||
export default class GenericPKCEAuthenticationPage extends React.Component {
|
||||
static propTypes = {
|
||||
inProgress: PropTypes.bool,
|
||||
config: PropTypes.object.isRequired,
|
||||
onLogin: PropTypes.func.isRequired,
|
||||
t: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
state = {};
|
||||
|
||||
componentDidMount() {
|
||||
// Manually validate PropTypes - React 19 breaking change
|
||||
PropTypes.checkPropTypes(
|
||||
GenericPKCEAuthenticationPage.propTypes,
|
||||
this.props,
|
||||
'prop',
|
||||
'GenericPKCEAuthenticationPage',
|
||||
);
|
||||
|
||||
const {
|
||||
base_url = '',
|
||||
app_id = '',
|
||||
auth_endpoint = 'oauth2/authorize',
|
||||
auth_token_endpoint = 'oauth2/token',
|
||||
} = this.props.config.backend;
|
||||
this.auth = new PkceAuthenticator({
|
||||
base_url,
|
||||
auth_endpoint,
|
||||
app_id,
|
||||
auth_token_endpoint,
|
||||
auth_token_endpoint_content_type: 'application/x-www-form-urlencoded; charset=utf-8',
|
||||
});
|
||||
// Complete authentication if we were redirected back to from the provider.
|
||||
this.auth.completeAuth((err, data) => {
|
||||
if (err) {
|
||||
this.setState({ loginError: err.toString() });
|
||||
return;
|
||||
}
|
||||
this.props.onLogin(data);
|
||||
});
|
||||
}
|
||||
|
||||
handleLogin = e => {
|
||||
e.preventDefault();
|
||||
this.auth.authenticate({ scope: 'https://api.github.com/repo openid email' }, (err, data) => {
|
||||
if (err) {
|
||||
this.setState({ loginError: err.toString() });
|
||||
return;
|
||||
}
|
||||
this.props.onLogin(data);
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
const { inProgress, config, t } = this.props;
|
||||
return (
|
||||
<AuthenticationPage
|
||||
onLogin={this.handleLogin}
|
||||
loginDisabled={inProgress}
|
||||
loginErrorMessage={this.state.loginError}
|
||||
logoUrl={config.logo_url} // Deprecated, replaced by `logo.src`
|
||||
logo={config.logo}
|
||||
siteUrl={config.site_url}
|
||||
renderButtonContent={() => (
|
||||
<React.Fragment>
|
||||
<LoginButtonIcon type="link" /> {inProgress ? t('auth.loggingIn') : t('auth.login')}
|
||||
</React.Fragment>
|
||||
)}
|
||||
t={t}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import * as React from 'react';
|
||||
import { GitHubBackend } from 'decap-cms-backend-github';
|
||||
import { PKCEAuthenticationPage } from 'decap-cms-ui-auth';
|
||||
|
||||
import type { GitHubUser } from 'decap-cms-backend-github/src/implementation';
|
||||
import type { Config } from 'decap-cms-lib-util/src';
|
||||
import type { Octokit } from '@octokit/rest';
|
||||
|
||||
export default class AwsCognitoGitHubProxyBackend extends GitHubBackend {
|
||||
constructor(config: Config, options = {}) {
|
||||
super(config, options);
|
||||
|
||||
this.bypassWriteAccessCheckForAppTokens = true;
|
||||
this.tokenKeyword = 'Bearer';
|
||||
}
|
||||
|
||||
authComponent() {
|
||||
const wrappedAuthenticationPage = (props: Record<string, unknown>) => {
|
||||
const allProps = { ...props, backend: this };
|
||||
return <PKCEAuthenticationPage {...allProps} />;
|
||||
};
|
||||
wrappedAuthenticationPage.displayName = 'AuthenticationPage';
|
||||
return wrappedAuthenticationPage;
|
||||
}
|
||||
|
||||
async currentUser({ token }: { token: string }): Promise<GitHubUser> {
|
||||
if (!this._currentUserPromise) {
|
||||
this._currentUserPromise = fetch(this.baseUrl + '/oauth2/userInfo', {
|
||||
headers: {
|
||||
Authorization: `${this.tokenKeyword} ${token}`,
|
||||
},
|
||||
}).then(async (res: Response): Promise<GitHubUser> => {
|
||||
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`,
|
||||
} as GitHubUser;
|
||||
});
|
||||
}
|
||||
return this._currentUserPromise;
|
||||
}
|
||||
|
||||
async getPullRequestAuthor(pullRequest: Octokit.PullsListResponseItem) {
|
||||
return pullRequest.user?.login;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { API } from 'decap-cms-backend-github';
|
||||
|
||||
import AwsCognitoGitHubProxyBackend from './implementation';
|
||||
|
||||
export const DecapCmsBackendAwsCognitoGithubProxy = {
|
||||
AwsCognitoGitHubProxyBackend,
|
||||
API,
|
||||
};
|
||||
|
||||
export { AwsCognitoGitHubProxyBackend, API };
|
||||
@@ -0,0 +1,3 @@
|
||||
const { getConfig } = require('../../scripts/webpack.js');
|
||||
|
||||
module.exports = getConfig();
|
||||
Reference in New Issue
Block a user