Skip to content

Commit

Permalink
fix: gitlab pkce auth error (#7110)
Browse files Browse the repository at this point in the history
  • Loading branch information
blackb1rd committed Feb 21, 2024
1 parent 016aca1 commit bcd58d6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
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
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
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
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

0 comments on commit bcd58d6

Please sign in to comment.