Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: gitlab pkce auth error #7110

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ export default class GenericPKCEAuthenticationPage extends React.Component {
app_id = '',
auth_endpoint = 'oauth2/authorize',
auth_token_endpoint = 'oauth2/token',
redirect_uri = document.location.origin + document.location.pathname,
} = this.props.config.backend;
this.auth = new PkceAuthenticator({
base_url,
auth_endpoint,
app_id,
auth_token_endpoint,
redirect_uri,
auth_token_endpoint_content_type: 'application/x-www-form-urlencoded; charset=utf-8',
});
// Complete authentication if we were redirected back to from the provider.
Expand Down
1 change: 0 additions & 1 deletion packages/decap-cms-backend-gitea/src/AuthenticationPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export default class GiteaAuthenticationPage extends React.Component {
app_id,
auth_token_endpoint: 'login/oauth/access_token',
auth_token_endpoint_content_type: 'application/json; charset=utf-8',
redirect_uri: document.location.origin + document.location.pathname,
});
// Complete authentication if we were redirected back to from the provider.
this.auth.completeAuth((err, data) => {
Expand Down
20 changes: 16 additions & 4 deletions packages/decap-cms-backend-gitlab/src/AuthenticationPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,30 @@ const LoginButtonIcon = styled(Icon)`
`;

const clientSideAuthenticators = {
pkce: ({ base_url, auth_endpoint, app_id, auth_token_endpoint }) =>
pkce: ({
base_url,
auth_endpoint,
app_id,
auth_token_endpoint}) =>
new PkceAuthenticator({
base_url,
auth_endpoint,
app_id,
auth_token_endpoint,
auth_token_endpoint_content_type: 'application/json; charset=utf-8',
redirect_uri: document.location.origin + document.location.pathname,
}),

implicit: ({ base_url, auth_endpoint, app_id, clearHash }) =>
new ImplicitAuthenticator({ base_url, auth_endpoint, app_id, clearHash }),
implicit: ({
base_url,
auth_endpoint,
app_id,
clearHash }) =>
new ImplicitAuthenticator({
base_url,
auth_endpoint,
app_id,
clearHash,
}),
};

export default class GitLabAuthenticationPage extends React.Component {
Expand Down
5 changes: 2 additions & 3 deletions packages/decap-cms-lib-auth/src/pkce-oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export default class PkceAuthenticator {
this.auth_url = `${baseURL}/${authEndpoint}`;
this.auth_token_url = `${baseURL}/${authTokenEndpoint}`;
this.auth_token_endpoint_content_type = config.auth_token_endpoint_content_type;
this.redirect_uri = trim(config.redirect_uri, '/');
this.appID = config.app_id;
}

Expand All @@ -65,7 +64,7 @@ export default class PkceAuthenticator {

const authURL = new URL(this.auth_url);
authURL.searchParams.set('client_id', this.appID);
authURL.searchParams.set('redirect_uri', this.redirect_uri);
authURL.searchParams.set('redirect_uri', document.location.origin + document.location.pathname);
authURL.searchParams.set('response_type', 'code');
authURL.searchParams.set('scope', options.scope);

Expand Down Expand Up @@ -118,7 +117,7 @@ export default class PkceAuthenticator {
client_id: this.appID,
code,
grant_type: 'authorization_code',
redirect_uri: this.redirect_uri,
redirect_uri: document.location.origin + document.location.pathname,
code_verifier: getCodeVerifier(),
};

Expand Down
Loading