planning
All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s

This commit is contained in:
2024-10-14 09:15:30 +02:00
parent bcba00a730
commit 6e64e138e2
21059 changed files with 2317811 additions and 1 deletions

View File

@@ -0,0 +1,74 @@
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() {
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}
siteUrl={config.site_url}
renderButtonContent={() => (
<React.Fragment>
<LoginButtonIcon type="link" /> {inProgress ? t('auth.loggingIn') : t('auth.login')}
</React.Fragment>
)}
t={t}
/>
);
}
}

View File

@@ -0,0 +1,52 @@
import * as React from 'react';
import { GitHubBackend } from 'decap-cms-backend-github';
import AuthenticationPage from './AuthenticationPage';
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>) => (
<AuthenticationPage {...props} backend={this} />
);
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;
}
}

View File

@@ -0,0 +1,12 @@
import { API } from 'decap-cms-backend-github';
import AwsCognitoGitHubProxyBackend from './implementation';
import AuthenticationPage from './AuthenticationPage';
export const DecapCmsBackendAwsCognitoGithubProxy = {
AwsCognitoGitHubProxyBackend,
API,
AuthenticationPage,
};
export { AwsCognitoGitHubProxyBackend, API, AuthenticationPage };