- Web-based Markdown formatter with real-time conversion - Microsoft Azure AD authentication with PKCE flow - Server-side JWT validation with httpOnly cookies - Clipboard functionality for HTML/text output - PHP backend with Composer dependency management - Comprehensive README with installation instructions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
6.5 KiB
Markdown Formatter
A secure web-based Markdown to HTML converter application with Microsoft Azure AD authentication. The application provides real-time Markdown processing with clipboard functionality, all protected behind enterprise-grade authentication.
Features
- Real-time Markdown Processing: Convert Markdown to HTML instantly as you type
- Secure Authentication: Microsoft Azure AD/Entra ID integration with PKCE flow
- Clipboard Integration: Copy HTML or plain text output with modern Clipboard API
- Server-side Security: JWT validation on all requests with httpOnly cookies
- Responsive Design: Clean, modern interface with Montserrat font
- Enterprise Ready: Stateless authentication suitable for production deployments
Architecture
Security-First Design
- Authentication Gateway: All pages require valid Azure AD authentication
- JWT Validation: Server-side token verification using Azure AD public keys
- httpOnly Cookies: Secure token storage preventing XSS attacks
- PKCE Flow: Authorization Code with Proof Key for Code Exchange
Technology Stack
- Frontend: Vanilla JavaScript, HTML5, CSS3
- Backend: PHP 7.4+ with Composer dependency management
- Authentication: MSAL.js + Azure AD
- Markdown Processing: marked.js library
- JWT Handling: Firebase JWT library
Prerequisites
- PHP 7.4 or higher with OpenSSL extension
- Composer (PHP dependency manager)
- Web server (Apache, Nginx, or PHP built-in server)
- Microsoft Azure AD tenant with app registration
- Modern web browser with JavaScript enabled
Installation
1. Clone the Repository
git clone <repository-url>
cd markdown-formatter
2. Install PHP Dependencies
composer install
This will install the Firebase JWT library required for token validation.
3. Azure AD App Registration
-
Go to Azure Portal
-
Navigate to Azure Active Directory → App registrations
-
Click New registration
-
Configure the application:
- Name: Markdown Formatter
- Supported account types: Accounts in this organizational directory only
- Redirect URI:
- Platform: Single-page application (SPA)
- URI:
http://localhost:8000(for local development)
-
After registration, note the Application (client) ID and Directory (tenant) ID
-
Configure API permissions:
- Add Microsoft Graph → User.Read (delegated)
- Grant admin consent if required
4. Update Configuration
The application is pre-configured with these Azure AD settings:
- Client ID:
9079054c-9620-4757-a256-23413042f1ef - Tenant ID:
e519c2e6-bc6d-4fdf-8d9c-923c2f002385
If you need to use different Azure AD settings, update the configuration in:
js/script.js(MSAL configuration)JWTValidator.php(tenant validation)
5. Start Local Development Server
php -S localhost:8000
6. Access the Application
Open your browser and navigate to:
http://localhost:8000
You will be redirected to Microsoft's login page for authentication.
File Structure
markdown-formatter/
├── index.php # Main application page (auth required)
├── auth.php # Authentication endpoint
├── process.php # Server-side processing (auth required)
├── config.php # PHP configuration
├── composer.json # PHP dependencies
├── AuthMiddleware.php # Authentication middleware
├── JWTValidator.php # JWT validation logic
├── js/
│ └── script.js # Client-side application logic
├── css/
│ └── style.css # Application styling
└── vendor/ # Composer dependencies
Authentication Flow
- Initial Access: User visits any page
- Authentication Check:
AuthMiddlewarevalidates httpOnly cookie - Login Redirect: Unauthenticated users see login page
- Azure AD Login: MSAL.js initiates popup-based PKCE flow
- Token Exchange: Valid Azure AD tokens stored as httpOnly cookies
- Page Reload: User redirected to requested page
- JWT Validation: Every request validates token against Azure AD
Development
Local Development Setup
- Ensure PHP OpenSSL extension is enabled:
php -m | grep openssl
- Start the development server:
php -S localhost:8000
- The application will be available at
http://localhost:8000
Dependency Management
Update PHP dependencies:
composer update
Testing Authentication
- Test with different browsers to verify cookie behavior
- Use browser developer tools to inspect authentication flow
- Check Network tab for JWT validation requests
Production Deployment
Server Requirements
- PHP 7.4+ with OpenSSL extension
- Web server with HTTPS support
- Composer for dependency management
Configuration Updates
- Azure AD Redirect URIs: Add your production domain
- HTTPS: Ensure all authentication flows use HTTPS
- Error Reporting: Disable in production (modify
config.php) - Cookie Settings: Verify httpOnly cookies work with your domain
Security Considerations
- Always use HTTPS in production
- Configure proper CORS policies if needed
- Monitor authentication logs for suspicious activity
- Regularly update dependencies for security patches
Usage
- Login: Click "Login with Microsoft" button
- Write Markdown: Type or paste Markdown in the left panel
- View HTML: Real-time conversion appears in the right panel
- Copy Output: Use clipboard buttons to copy HTML or plain text
- Logout: Click logout to clear authentication
Troubleshooting
Common Issues
Authentication fails with popup blocked
- Allow popups for your domain in browser settings
- Try using incognito/private browsing mode
JWT validation errors
- Verify system clock is synchronized
- Check that OpenSSL extension is enabled
- Ensure network connectivity to Azure AD
Clipboard functionality not working
- Modern browsers require HTTPS for Clipboard API
- Fallback uses document.execCommand for HTTP
Dependencies missing
- Run
composer installto install required packages - Verify PHP version meets minimum requirements
Debug Mode
Enable detailed error reporting by modifying config.php:
error_reporting(E_ALL);
ini_set('display_errors', 1);
License
[Add your license information here]
Support
[Add your support contact information here]