google-oauth-cli-generator
Version:
CLI tool to quickly set up Google OAuth authentication for hackathons and projects
47 lines • 1.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateGoogleCredentials = validateGoogleCredentials;
exports.isValidUrl = isValidUrl;
exports.validateProjectName = validateProjectName;
exports.sanitizeProjectName = sanitizeProjectName;
const url_1 = require("url");
function validateGoogleCredentials(config) {
// Validate Client ID format
if (!config.clientId.includes('.apps.googleusercontent.com')) {
throw new Error('Invalid Google Client ID format');
}
// Validate Client Secret length (Google secrets are typically 24+ chars)
if (config.clientSecret.length < 20) {
throw new Error('Google Client Secret seems too short');
}
// Validate Redirect URI
if (!isValidUrl(config.redirectUri)) {
throw new Error('Invalid Redirect URI format');
}
return true;
}
function isValidUrl(urlString) {
try {
// Try using the URL constructor
const url = new url_1.URL(urlString);
// Ensure it's http or https
return url.protocol === 'http:' || url.protocol === 'https:';
}
catch {
// Fallback to regex validation if URL constructor fails
const urlRegex = /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$/;
return urlRegex.test(urlString);
}
}
function validateProjectName(name) {
const validPattern = /^[a-zA-Z0-9-_]+$/;
return validPattern.test(name) && name.length > 0;
}
function sanitizeProjectName(name) {
return name
.toLowerCase()
.replace(/[^a-zA-Z0-9-_]/g, '-')
.replace(/--+/g, '-')
.replace(/^-|-$/g, '');
}
//# sourceMappingURL=validation.js.map