Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
# Mono auto generated files
mono_crash.*

#App JSON file
app.json

# Build results
[Dd]ebug/
[Dd]ebugPublic/
Expand Down
31 changes: 31 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,35 @@ fileignoreconfig:
checksum: f3bd8c6e981ed0acf26432859b2b7e388c0d90018513005cfc674726f14fe245
- filename: ui/src/components/SchemaModal/index.tsx
checksum: 607a465c9cd4a504b9a81750a3f9faa0f4e11c09414354d69ec7308c11f0046a

fileignoreconfig:
- filename: api/sso.utils.js
checksum: 5d589c128c4b38f8aacd70e5d02ddd7fa8e93ff7897ca69a1258378139d1d616
version: "1.0"

fileignoreconfig:
- filename: api/package-lock.json
checksum: 4d2fd1905b5933e1d2c4d178e1536422d4aac84caa9640149eab0432a75b712d
- filename: api/src/services/migration.service.ts
checksum: 1fdf5423840e170709c7c677c3a6a7c6ae61f373948c2ef295aa645a859c1af5
- filename: api/src/services/contentMapper.service.ts
checksum: 03d5dcc31b38fd435f6a4389d6891c7fc1ba27b32dc2b382b91173d84f4565f7
- filename: api/src/services/globalField.service.ts
checksum: b808815c7372f68fe9a5904d23be50cb0ec066592328ec1721dc3c395cbe3a2c
- filename: api/src/services/taxonomy.service.ts
checksum: 840ab11838ebf08df44ada0a3674dad8cc124bc8bcbc5dfd1d9c585a34e4aeda
- filename: api/src/services/org.service.ts
checksum: 0a50297164d7845d889fc78097164c4794a3f9cd7314c06365c8426a2a6ee52a
- filename: ui/src/pages/Login/index.tsx
checksum: 7f7c008586db60f1cc8df625b88bfdc5c3bb861c21e40a55fc763f0ac4a6a8d2
version: "1.0"

fileignoreconfig:
- filename: api/src/services/contentMapper.service.ts
checksum: 924b124214a93a7bec4c471304f5b270d5e735d506644180273b7118f3d37dd2
version: "1.0"

fileignoreconfig:
- filename: ui/src/pages/Login/index.tsx
checksum: 213c6441dc87d82ce6b97679d457ae56c6e40ef13a89bddd4f21afcf566b5576
version: "1.0"
3 changes: 1 addition & 2 deletions api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -366,5 +366,4 @@ database/
/cmsMigrationData
/migration-data
**/copy*
**copy.ts
manifest.json
**copy.ts
100 changes: 99 additions & 1 deletion api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"lint:fix": "eslint --ext .ts --ignore-pattern './node_modules/' --ignore-pattern './dist/'",
"precommit": "npm run prettify && npm run lint:fix"
},
"type": "module",
"repository": {
"type": "git",
"url": "git+https://github.com/contentstack/migration-v2.git"
Expand Down Expand Up @@ -59,6 +58,7 @@
"devDependencies": {
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/express-session": "^1.18.2",
"@types/fs-extra": "^11.0.4",
"@types/fs-readdir-recursive": "^1.1.3",
"@types/jsdom": "^21.1.7",
Expand Down
15 changes: 15 additions & 0 deletions api/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ export const DEVURLS: any = {
AU: "au-developerhub-api.contentstack.com",
GCP_EU: "gcp-eu-developerhub-api.contentstack.com",
};
export const CSAUTHHOST: any = {
NA:"https://app.contentstack.com/apps-api/token",
EU:"https://eu-app.contentstack.com/apps-api/token",
AZURE_NA:"https://azure-na-app.contentstack.com/apps-api/token",
AZURE_EU:"https://azure-eu-app.contentstack.com/apps-api/token",
GCP_NA:"https://gcp-na-app.contentstack.com/apps-api/token",
}

export const regionalApiHosts = {
NA: 'api.contentstack.io',
EU: 'eu-api.contentstack.com',
AZURE_NA: 'azure-na-api.contentstack.com',
AZURE_EU: 'azure-eu-api.contentstack.com',
GCP_NA: 'gcp-na-api.contentstack.com'
};
export const CMS = {
CONTENTFUL: "contentful",
SITECORE_V8: "sitecore v8",
Expand Down
101 changes: 101 additions & 0 deletions api/src/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Request, Response } from "express";
import { authService } from "../services/auth.service.js";
import { HTTP_CODES } from "../constants/index.js";

/**
* Handles the login request.
Expand All @@ -23,7 +24,107 @@ const RequestSms = async (req: Request, res: Response) => {
res.status(resp.status).json(resp.data);
};


/**
* Generates the OAuth token and saves it to the database.
* @param req - The request object. Sends the code and region.
* @param res - The response object. Sends the message "Token received successfully."
*/
const saveOAuthToken = async (req: Request, res: Response) => {
await authService.saveOAuthToken(req);
res.status(HTTP_CODES.OK).json({ message: "Token received successfully." });
};


/**
* Handles the request for getting the app configuration.
*
* @param req - The request object.
* @param res - The response object.
*/
export const getAppConfigHandler = async (req: Request, res: Response): Promise<void> => {
try {
const appConfig = await authService.getAppData();
res.status(200).json(appConfig);

} catch (error: any) {
console.error('Error in getAppConfig controller:', error);

if (error?.message?.includes('app.json file not found')) {
res.status(404).json({
error: 'SSO configuration not found',
message: 'app.json file does not exist'
});
return;
}

if (error?.message?.includes('Invalid JSON format')) {
res.status(400).json({
error: 'Invalid SSO configuration',
message: 'app.json contains invalid JSON'
});
return;
}

res.status(500).json({
error: 'Server error',
message: 'Unable to read SSO configuration'
});
}
};

/**
* Handles the request for checking the SSO authentication status.
*
* @param req - The request object.
* @param res - The response object.
*/
export const getSSOAuthStatus = async (req: Request, res: Response): Promise<void> => {
try {
const { userId } = req.params;

if (!userId) {
res.status(400).json({
error: 'Missing user ID',
message: 'User ID parameter is required'
});
return;
}

const authStatus = await authService.checkSSOAuthStatus(userId);

res.status(200).json(authStatus);

} catch (error: any) {
console.error('Error in getSSOAuthStatus controller:', error);

if (error?.message?.includes('User not found in authentication records')) {
res.status(404).json({
error: 'User not found',
message: 'User not found in authentication records'
});
return;
}

if (error?.message?.includes('SSO authentication not completed')) {
res.status(202).json({
authenticated: false,
message: 'SSO authentication not completed'
});
return;
}

res.status(500).json({
error: 'Server error',
message: 'Unable to check SSO authentication status'
});
}
};

export const authController = {
login,
RequestSms,
saveOAuthToken,
getAppConfigHandler,
getSSOAuthStatus
};
1 change: 1 addition & 0 deletions api/src/models/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface AuthenticationDocument {
authtoken: string;
created_at: string;
updated_at: string;
access_token: string;
}[];
}

Expand Down
Loading