Skip to content

Commit

Permalink
Merge pull request middlewarehq#569 from middlewarehq/fix/gitlab-toke…
Browse files Browse the repository at this point in the history
…n-validaity

Refactor GitLab validity check to include custom domain support
  • Loading branch information
shivam-bit authored Oct 4, 2024
2 parents 9f5f552 + 6c83ce5 commit e2d9963
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ export const ConfigureGitlabModalBody: FC<{

const checkDomainWithRegex = (domain: string) => {
const regex =
/^(https:\/\/)?[a-zA-Z0-9]+([-.][a-zA-Z0-9]+)*\.[a-zA-Z]{2,}(:[0-9]{1,5})?(\/.*)?$/;
/^(https?:\/\/)[a-zA-Z0-9]+([-.][a-zA-Z0-9]+)*\.[a-zA-Z]{2,}(:[0-9]{1,5})?(\/.*)?$/;
return regex.test(domain);
};

const handleTokenChange = (e: string) => {
token.set(e);
showScopeError.set('');
Expand Down Expand Up @@ -79,7 +78,7 @@ export const ConfigureGitlabModalBody: FC<{
}

depFn(isLoading.true);
await checkGitLabValidity(token.value)
await checkGitLabValidity(token.value, customDomain.value)
.then(async (res) => {
return res;
})
Expand Down
8 changes: 6 additions & 2 deletions web-server/src/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ export const getMissingPATScopes = async (pat: string) => {

// Gitlab functions

export const checkGitLabValidity = async (accessToken: string) => {
const url = 'https://gitlab.com/api/v4/personal_access_tokens/self';
export const checkGitLabValidity = async (
accessToken: string,
customDomain?: string
) => {
const baseUrl = customDomain || 'https://gitlab.com';
const url = `${baseUrl}/api/v4/personal_access_tokens/self`;
try {
const response = await axios.get(url, {
headers: {
Expand Down

0 comments on commit e2d9963

Please sign in to comment.