use auth_framework::{AuthConfig, AuthFramework, api::ApiServer};
use std::sync::Arc;
use tracing::info;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt::init();
info!("🚀 Starting OAuth2 Authorization Server Test");
let config = AuthConfig::new()
.secret("test_oauth2_secret_key_that_is_long_enough_for_secure_operation".to_string());
let mut auth_framework = AuthFramework::new(config);
auth_framework.initialize().await?;
let auth_framework = Arc::new(auth_framework);
let server = ApiServer::new(auth_framework.clone());
info!("📖 OAuth2 Endpoints Available:");
info!(" Authorization: GET http://127.0.0.1:8080/api/v1/oauth/authorize");
info!(" Token: POST http://127.0.0.1:8080/api/v1/oauth/token");
info!(" Revoke: POST http://127.0.0.1:8080/api/v1/oauth/revoke");
info!(" UserInfo: GET http://127.0.0.1:8080/api/v1/oauth/userinfo");
info!("");
info!("🔍 Testing OAuth2 Authorization Code Flow:");
info!(
"1. GET /api/v1/oauth/authorize?response_type=code&client_id=test_client&redirect_uri=http://localhost:3000/callback&scope=openid%20profile&state=xyz"
);
info!("2. Use returned authorization_url to get code");
info!("3. POST /api/v1/oauth/token with authorization_code grant");
info!("4. Use access_token for authenticated requests");
info!("");
info!("🔐 PKCE Support:");
info!(" Add code_challenge and code_challenge_method=S256 to authorization request");
info!(" Include code_verifier in token request");
info!("");
info!("🌐 Starting server on http://127.0.0.1:8080");
server.start().await?;
Ok(())
}