Buckets:
| #!/usr/bin/env python3 | |
| """ | |
| π Teste Manual Completo - Biblioteca OIDC Python | |
| ================================================= | |
| Script interativo para testar autenticaΓ§Γ£o: | |
| - Keycloak e Google OAuth | |
| - ValidaΓ§Γ£o de tokens (ID Token e Access Token) | |
| - InformaΓ§Γ΅es do usuΓ‘rio | |
| - Porta unificada: 5400 | |
| """ | |
| import threading | |
| import time | |
| import webbrowser | |
| from dataclasses import asdict | |
| from datetime import datetime | |
| from http.server import BaseHTTPRequestHandler, HTTPServer | |
| from urllib.parse import parse_qs, urlparse | |
| from oidc_config import create_oidc_client, get_oidc_config, list_available_providers | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # CALLBACK SERVER | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| callback_data = { | |
| "code": None, | |
| "state": None, | |
| "error": None, | |
| "error_description": None, | |
| "received": False, | |
| "full_path": None, | |
| } | |
| class CallbackHandler(BaseHTTPRequestHandler): | |
| """Handler para processar callback OAuth2/OIDC.""" | |
| def log_message(self, format, *args): | |
| """Suprimir logs padrΓ£o do servidor HTTP.""" | |
| pass | |
| def do_GET(self): | |
| """Processa requisiΓ§Γ£o GET do callback.""" | |
| global callback_data | |
| # Ignorar requisiΓ§Γ΅es para favicon, assets, etc | |
| if self.path.startswith("/favicon") or self.path.startswith("/static"): | |
| self.send_response(404) | |
| self.end_headers() | |
| return | |
| # Parse da URL e query string | |
| parsed = urlparse(self.path) | |
| params = parse_qs(parsed.query) | |
| # DEBUG: Mostrar o que foi recebido | |
| print("\nπ DEBUG - Callback recebido:") | |
| print(f" Path completo: {self.path}") | |
| print(f" Query params: {dict(params)}") | |
| # Extrair parΓ’metros do callback | |
| callback_data["code"] = params.get("code", [None])[0] | |
| callback_data["state"] = params.get("state", [None])[0] | |
| callback_data["error"] = params.get("error", [None])[0] | |
| callback_data["error_description"] = params.get("error_description", [None])[0] | |
| callback_data["full_path"] = self.path | |
| callback_data["received"] = True | |
| # DEBUG: Mostrar o que foi extraΓdo | |
| print( | |
| f" Code extraΓdo: {callback_data['code'][:30] if callback_data['code'] else 'None'}..." | |
| ) | |
| print( | |
| f" State extraΓdo: {callback_data['state'][:30] if callback_data['state'] else 'None'}..." | |
| ) | |
| print(f" Error: {callback_data['error']}") | |
| print() | |
| # Preparar resposta HTML | |
| self.send_response(200) | |
| self.send_header("Content-type", "text/html; charset=utf-8") | |
| self.end_headers() | |
| if callback_data["error"]: | |
| html = f""" | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Erro de AutenticaΓ§Γ£o</title> | |
| <style> | |
| body {{ | |
| font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif; | |
| max-width: 600px; | |
| margin: 50px auto; | |
| padding: 20px; | |
| background: #ffebee; | |
| }} | |
| .error {{ | |
| background: #c62828; | |
| color: white; | |
| padding: 30px; | |
| border-radius: 8px; | |
| box-shadow: 0 2px 10px rgba(0,0,0,0.1); | |
| }} | |
| h1 {{margin-top: 0;}} | |
| </style> | |
| </head> | |
| <body> | |
| <div class="error"> | |
| <h1>β Erro na AutenticaΓ§Γ£o</h1> | |
| <p><strong>Erro:</strong> {callback_data["error"]}</p> | |
| <p><strong>DescriΓ§Γ£o:</strong> {callback_data.get("error_description", "N/A")}</p> | |
| </div> | |
| </body> | |
| </html> | |
| """ | |
| else: | |
| html = """ | |
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>AutenticaΓ§Γ£o ConcluΓda</title> | |
| <style> | |
| body { | |
| font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif; | |
| max-width: 600px; | |
| margin: 50px auto; | |
| padding: 20px; | |
| background: #e8f5e9; | |
| } | |
| .success { | |
| background: #2e7d32; | |
| color: white; | |
| padding: 30px; | |
| border-radius: 8px; | |
| box-shadow: 0 2px 10px rgba(0,0,0,0.1); | |
| } | |
| h1 {margin-top: 0;} | |
| </style> | |
| </head> | |
| <body> | |
| <div class="success"> | |
| <h1>β AutenticaΓ§Γ£o ConcluΓda com Sucesso!</h1> | |
| <p>O token de acesso foi recebido.</p> | |
| <p><strong>VocΓͺ pode fechar esta janela e retornar ao terminal.</strong></p> | |
| </div> | |
| </body> | |
| </html> | |
| """ | |
| self.wfile.write(html.encode("utf-8")) | |
| def reset_callback_data(): | |
| """Reseta os dados do callback para novo uso.""" | |
| callback_data["code"] = None | |
| callback_data["state"] = None | |
| callback_data["error"] = None | |
| callback_data["error_description"] = None | |
| callback_data["received"] = False | |
| callback_data["full_path"] = None | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # VALIDAΓΓO E DECODIFICAΓΓO DE TOKENS | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| def decode_and_display_token(client, token_string: str, token_type: str = "Token"): | |
| """ | |
| Decodifica e exibe informaΓ§Γ΅es de um token JWT. | |
| Args: | |
| client: Cliente OIDC | |
| token_string: String do token JWT | |
| token_type: Tipo do token ("ID Token" ou "Access Token") | |
| """ | |
| print(f"\n π Decodificando {token_type}...") | |
| try: | |
| claims = client.decode_token(token_string) | |
| print(f" β {token_type} vΓ‘lido!") | |
| print(f"\n CLAIMS DO {token_type.upper()}:") | |
| print(" " + "β" * 66) | |
| # Claims importantes para exibir | |
| important_claims = [ | |
| "sub", | |
| "iss", | |
| "aud", | |
| "azp", | |
| "exp", | |
| "iat", | |
| "email", | |
| "email_verified", | |
| "name", | |
| "preferred_username", | |
| "scope", | |
| "given_name", | |
| "family_name", | |
| ] | |
| for claim in important_claims: | |
| if claim in claims: | |
| value = claims[claim] | |
| # Formatar timestamps | |
| if claim in ["exp", "iat"]: | |
| try: | |
| dt = datetime.fromtimestamp(value) | |
| value_str = f"{value} ({dt.strftime('%Y-%m-%d %H:%M:%S')})" | |
| except: | |
| value_str = str(value) | |
| else: | |
| value_str = str(value) | |
| if len(value_str) > 60: | |
| value_str = value_str[:60] + "..." | |
| print(f" {claim:20s}: {value_str}") | |
| # Mostrar outros claims (atΓ© 5) | |
| other_claims = {k: v for k, v in claims.items() if k not in important_claims} | |
| if other_claims: | |
| print("\n Outros claims:") | |
| for claim, value in list(other_claims.items())[:5]: | |
| value_str = str(value) | |
| if len(value_str) > 60: | |
| value_str = value_str[:60] + "..." | |
| print(f" {claim:20s}: {value_str}") | |
| print(" " + "β" * 66) | |
| except Exception as e: | |
| print(f" β οΈ Erro ao decodificar: {e}") | |
| def validate_and_display_tokens(client, token, provider: str): | |
| """ | |
| Valida e exibe informaΓ§Γ΅es completas dos tokens. | |
| Args: | |
| client: Cliente OIDC | |
| token: Objeto TokenResponse com tokens | |
| provider: Nome do provedor | |
| """ | |
| print(f"\nπ VALIDAΓΓO DOS TOKENS ({provider.upper()}):") | |
| print(" " + "β" * 66) | |
| # Validar ID Token | |
| if token.id_token: | |
| decode_and_display_token(client, token.id_token, "ID Token") | |
| # Validar Access Token (se for JWT) | |
| if token.access_token: | |
| parts = token.access_token.split(".") | |
| if len(parts) == 3: # Γ um JWT | |
| decode_and_display_token(client, token.access_token, "Access Token") | |
| else: | |
| print("\n βΉοΈ Access Token Γ© opaco (nΓ£o Γ© JWT)") | |
| print(f" Token: {token.access_token[:50]}...") | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # FUNΓΓES DE TESTE | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| def test_keycloak(): | |
| """Testa autenticaΓ§Γ£o com Keycloak.""" | |
| return test_provider("keycloak") | |
| def test_google(): | |
| """Testa autenticaΓ§Γ£o com Google OAuth.""" | |
| return test_provider("google") | |
| def test_github(): | |
| """Testa autenticaΓ§Γ£o com GitHub OAuth.""" | |
| return test_provider("github") | |
| def test_provider(provider: str) -> bool: | |
| """ | |
| Testa autenticaΓ§Γ£o com um provedor especΓfico. | |
| Args: | |
| provider: Nome do provedor ('keycloak', 'google', etc.) | |
| Returns: | |
| bool: True se autenticaΓ§Γ£o foi bem sucedida | |
| """ | |
| print("\n" + "=" * 70) | |
| print(f" π TESTE: {provider.upper()}") | |
| print("=" * 70) | |
| try: | |
| # Obter configuraΓ§Γ£o | |
| print("\nπ ConfiguraΓ§Γ£o:") | |
| config = get_oidc_config(provider) | |
| print(f" Issuer URL: {config.issuer_url}") | |
| print(f" Client ID: {config.client_id[:30]}...") | |
| print(f" Redirect URI: {config.redirect_uri}") | |
| print(f" Scopes: {config.scopes}") | |
| # Verificar porta | |
| parsed_uri = urlparse(config.redirect_uri) | |
| port = parsed_uri.port or 5400 | |
| print(f"\nπ Porta configurada: {port}") | |
| print(f" β οΈ IMPORTANTE: O redirect URI '{config.redirect_uri}'") | |
| print(" deve estar registrado exatamente assim no provedor!") | |
| # Criar cliente OIDC | |
| print("\nπ§ Criando cliente OIDC...") | |
| client = create_oidc_client(provider) | |
| print(" β Cliente criado") | |
| # Iniciar servidor de callback | |
| print(f"\nπ Iniciando servidor de callback na porta {port}...") | |
| try: | |
| server = HTTPServer(("localhost", port), CallbackHandler) | |
| print(" β Servidor iniciado") | |
| except OSError: | |
| print(f" β Erro: Porta {port} jΓ‘ estΓ‘ em uso") | |
| print("\nπ‘ SoluΓ§Γ£o: Execute o comando abaixo para liberar a porta:") | |
| print(f" kill -9 $(lsof -ti:{port})") | |
| return False | |
| # Iniciar servidor em thread separada | |
| thread = threading.Thread(target=server.serve_forever, daemon=True) | |
| thread.start() | |
| # Gerar URL de autorizaΓ§Γ£o | |
| print("\nπ Gerando URL de autorizaΓ§Γ£o...") | |
| auth_url, state, verifier = client.get_authorization_url() | |
| print(" β URL gerada") | |
| print(f" State: {state[:30]}...") | |
| if verifier: | |
| print(f" Code Verifier: {verifier[:30]}...") | |
| # DEBUG: Mostrar URL completa (primeiros 150 caracteres) | |
| print("\nπ DEBUG - URL de autorizaΓ§Γ£o:") | |
| print(f" {auth_url[:150]}...") | |
| # Abrir navegador | |
| print("\nπ Abrindo navegador para autenticaΓ§Γ£o...") | |
| print("\n" + "β" * 70) | |
| print("π FAΓA LOGIN NO NAVEGADOR QUE SERΓ ABERTO") | |
| print(" (Se o navegador nΓ£o abrir, copie a URL acima)") | |
| print("β" * 70) | |
| webbrowser.open(auth_url) | |
| # Aguardar callback (timeout de 120 segundos) | |
| print("\nβ³ Aguardando autenticaΓ§Γ£o...") | |
| for i in range(120): | |
| if callback_data["received"]: | |
| break | |
| time.sleep(1) | |
| if i > 0 and i % 10 == 0: | |
| print(f" ... aguardando ({i}s)") | |
| # Encerrar servidor | |
| server.shutdown() | |
| # DEBUG: Mostrar estado do callback apΓ³s espera | |
| print("\nπ DEBUG - Estado do callback:") | |
| print(f" Received: {callback_data['received']}") | |
| print(f" Code: {callback_data['code'][:30] if callback_data['code'] else 'None'}...") | |
| print(f" State: {callback_data['state'][:30] if callback_data['state'] else 'None'}...") | |
| print(f" Error: {callback_data['error']}") | |
| print(f" Full path: {callback_data['full_path']}") | |
| # Verificar se recebeu callback | |
| if not callback_data["received"]: | |
| print("\nβ Timeout - callback nΓ£o foi recebido apΓ³s 120s") | |
| print("\nπ‘ Verifique:") | |
| print(f" - O Redirect URI '{config.redirect_uri}' estΓ‘ registrado no provedor") | |
| print(" - VocΓͺ completou o login no navegador") | |
| return False | |
| # Verificar erros | |
| if callback_data["error"]: | |
| print(f"\nβ Erro: {callback_data['error']}") | |
| if callback_data.get("error_description"): | |
| print(f" DescriΓ§Γ£o: {callback_data['error_description']}") | |
| return False | |
| # Verificar cΓ³digo de autorizaΓ§Γ£o | |
| if not callback_data["code"]: | |
| print("\nβ CΓ³digo de autorizaΓ§Γ£o nΓ£o foi recebido") | |
| print("\nπ‘ POSSΓVEIS CAUSAS:") | |
| print(" 1. O Redirect URI nΓ£o estΓ‘ registrado corretamente no provedor") | |
| print(f" Esperado: {config.redirect_uri}") | |
| print(" 2. VocΓͺ negou a autorizaΓ§Γ£o no navegador") | |
| print(" 3. O provedor estΓ‘ retornando erro (verifique navegador)") | |
| print(" 4. Problema de rede ou firewall") | |
| print(f"\n Full path recebido: {callback_data.get('full_path', 'N/A')}") | |
| return False | |
| print("\nβ Callback recebido!") | |
| print(f" Code: {callback_data['code'][:30]}...") | |
| # Trocar cΓ³digo por tokens | |
| print("\nπ« Trocando cΓ³digo de autorizaΓ§Γ£o por tokens...") | |
| callback_url = f"http://localhost:{port}{callback_data['full_path']}" | |
| token = client.handle_authorization_response( | |
| callback_url, expected_state=state, code_verifier=verifier | |
| ) | |
| print(" β Tokens obtidos!") | |
| # Exibir informaΓ§Γ΅es dos tokens | |
| print("\n π INFORMAΓΓES DOS TOKENS:") | |
| print(" " + "β" * 66) | |
| print(f" Access Token: {token.access_token[:50]}...") | |
| print(f" Token Type: {token.token_type}") | |
| if token.expires_in: | |
| print(f" Expires In: {token.expires_in}s ({token.expires_in // 60} minutos)") | |
| else: | |
| print(" Expires In: N/A (provedor nΓ£o informou)") | |
| if token.id_token: | |
| print(f" ID Token: {token.id_token[:50]}...") | |
| if token.refresh_token: | |
| print(f" Refresh Token: {token.refresh_token[:50]}...") | |
| if token.scope: | |
| print(f" Scope: {token.scope}") | |
| print(" " + "β" * 66) | |
| # Validar e decodificar tokens | |
| validate_and_display_tokens(client, token, provider) | |
| # Obter informaΓ§Γ΅es do usuΓ‘rio | |
| print("\nπ€ Obtendo informaΓ§Γ΅es do usuΓ‘rio...") | |
| user_info = client.get_user_info(token.access_token) | |
| print(" β InformaΓ§Γ΅es obtidas!") | |
| # Exibir dados do usuΓ‘rio | |
| print("\n π DADOS DO USUΓRIO AUTENTICADO:") | |
| print(" " + "β" * 66) | |
| # Converter UserInfo para dicionΓ‘rio | |
| user_dict = asdict(user_info) | |
| claims_extra = user_dict.pop("claims", {}) | |
| user_dict.update(claims_extra) | |
| # Campos importantes | |
| user_fields = [ | |
| "sub", | |
| "name", | |
| "given_name", | |
| "family_name", | |
| "email", | |
| "email_verified", | |
| "preferred_username", | |
| "picture", | |
| "locale", | |
| ] | |
| for field in user_fields: | |
| if field in user_dict and user_dict[field] is not None: | |
| value = user_dict[field] | |
| if field == "picture" and len(str(value)) > 50: | |
| value = str(value)[:50] + "..." | |
| print(f" {field:20s}: {value}") | |
| # Outros campos adicionais | |
| other_fields = { | |
| k: v for k, v in user_dict.items() if k not in user_fields and v is not None | |
| } | |
| if other_fields: | |
| print("\n Campos adicionais:") | |
| for field, value in list(other_fields.items())[:5]: | |
| value_str = str(value) | |
| if len(value_str) > 50: | |
| value_str = value_str[:50] + "..." | |
| print(f" {field:20s}: {value_str}") | |
| print(" " + "β" * 66) | |
| # Resumo final | |
| print("\n" + "=" * 70) | |
| print(f" β SUCESSO - {provider.upper()} AUTENTICADO!") | |
| print("=" * 70) | |
| print("\nπ Resumo:") | |
| user_id = ( | |
| user_dict.get("email") | |
| or user_dict.get("preferred_username") | |
| or user_dict.get("sub", "N/A") | |
| ) | |
| print(f" β UsuΓ‘rio: {user_id}") | |
| if token.expires_in: | |
| print(f" β Token vΓ‘lido por: {token.expires_in}s ({token.expires_in // 60} min)") | |
| print(" β Tokens validados e decodificados com sucesso") | |
| print(f" β Provedor: {provider.upper()}") | |
| return True | |
| except Exception as e: | |
| print(f"\nβ Erro: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| return False | |
| finally: | |
| reset_callback_data() | |
| def list_providers(): | |
| """Lista todos os provedores disponΓveis.""" | |
| print("\n" + "=" * 70) | |
| print(" π PROVEDORES DISPONΓVEIS") | |
| print("=" * 70) | |
| try: | |
| providers = list_available_providers() | |
| if not providers: | |
| print("\nβ οΈ Nenhum provedor configurado no .env") | |
| print("\nπ‘ Configure ao menos um provedor no arquivo .env:") | |
| print(" - {PROVIDER}_ISSUER_URL") | |
| print(" - {PROVIDER}_CLIENT_ID") | |
| print(" - {PROVIDER}_REDIRECT_URI") | |
| return | |
| print(f"\nβ {len(providers)} provedor(es) configurado(s):\n") | |
| for provider in sorted(providers): | |
| try: | |
| config = get_oidc_config(provider) | |
| print(f" πΉ {provider.upper()}") | |
| print(f" Issuer: {config.issuer_url}") | |
| print(f" Client ID: {config.client_id[:30]}...") | |
| print(f" Redirect: {config.redirect_uri}") | |
| print(f" Scopes: {config.scopes}") | |
| print() | |
| except Exception as e: | |
| print(f" β οΈ {provider.upper()}: Erro ao carregar ({e})") | |
| print() | |
| except Exception as e: | |
| print(f"\nβ Erro: {e}") | |
| def show_env_guide(): | |
| """Mostra guia de como configurar provedores no .env.""" | |
| print("\n" + "=" * 70) | |
| print(" π GUIA: CONFIGURAR PROVEDORES NO .ENV") | |
| print("=" * 70) | |
| print(""" | |
| Para adicionar um provedor OIDC, adicione ao arquivo .env: | |
| {PROVIDER}_ISSUER_URL=https://issuer.exemplo.com | |
| {PROVIDER}_CLIENT_ID=seu-client-id | |
| {PROVIDER}_CLIENT_SECRET=seu-client-secret # Opcional | |
| {PROVIDER}_REDIRECT_URI=http://localhost:5400/callback | |
| {PROVIDER}_SCOPES=openid profile email # Opcional | |
| Onde {PROVIDER} pode ser: KEYCLOAK, GOOGLE, MICROSOFT, OKTA, etc. | |
| ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| EXEMPLO - Google OAuth: | |
| GOOGLE_ISSUER_URL=https://accounts.google.com | |
| GOOGLE_CLIENT_ID=123456789.apps.googleusercontent.com | |
| GOOGLE_CLIENT_SECRET=GOCSPX-abcdef123456 | |
| GOOGLE_REDIRECT_URI=http://localhost:5400/callback | |
| GOOGLE_SCOPES=openid profile email | |
| ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| EXEMPLO - GitHub OAuth (GRATUITO): | |
| GITHUB_ISSUER_URL=https://github.com | |
| GITHUB_CLIENT_ID=Iv1.a1b2c3d4e5f6g7h8 | |
| GITHUB_CLIENT_SECRET=abc123def456ghi789jkl012mno345pqr678 | |
| GITHUB_REDIRECT_URI=http://localhost:5400/callback | |
| GITHUB_SCOPES=user:email read:user | |
| β οΈ Configure em: https://github.com/settings/developers | |
| ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| EXEMPLO - Keycloak: | |
| KEYCLOAK_ISSUER_URL=https://sso.exemplo.com/auth/realms/meu-realm | |
| KEYCLOAK_CLIENT_ID=minha-app | |
| KEYCLOAK_CLIENT_SECRET=1234-5678-abcd-efgh | |
| KEYCLOAK_REDIRECT_URI=http://localhost:5400/callback | |
| KEYCLOAK_SCOPES=openid profile email | |
| ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| β οΈ IMPORTANTE: | |
| β’ Todos os Redirect URIs devem estar registrados no provedor | |
| β’ Use porta 5400 (ou ajuste conforme necessΓ‘rio) | |
| β’ O client_secret Γ© opcional para fluxos pΓΊblicos (PKCE) | |
| π Mais informaΓ§Γ΅es: consulte README.md ou arquivo .env.example | |
| """) | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # MENU PRINCIPAL | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| def show_menu(): | |
| """Exibe o menu principal.""" | |
| print("\n" + "=" * 70) | |
| print(" π TESTE MANUAL - BIBLIOTECA OIDC PYTHON") | |
| print("=" * 70) | |
| print(""" | |
| Este script permite testar autenticaΓ§Γ£o OIDC/OAuth2 de forma interativa. | |
| TESTES DE AUTENTICAΓΓO: | |
| [1] π Testar Keycloak | |
| [2] π Testar Google OAuth | |
| [3] οΏ½ Testar GitHub OAuth | |
| [4] π Testar mΓΊltiplos provedores | |
| GERENCIAMENTO: | |
| [5] π Listar provedores disponΓveis | |
| [6] π Guia para configurar provedores no .env | |
| SAIR: | |
| [0] β Sair | |
| β οΈ IMPORTANTE: | |
| β’ Os Redirect URIs devem estar registrados nos provedores | |
| β’ Porta padrΓ£o: 5400 (http://localhost:5400/callback) | |
| β’ Se necessΓ‘rio, libere a porta: kill -9 $(lsof -ti:5400) | |
| """) | |
| def main_menu(): | |
| """Loop principal do menu.""" | |
| choice = input("Escolha uma opΓ§Γ£o: ").strip() | |
| if choice == "0": | |
| print("\nπ AtΓ© logo!") | |
| return False | |
| elif choice == "1": | |
| success = test_keycloak() | |
| print(f"\n{'β Sucesso' if success else 'β Falhou'}") | |
| elif choice == "2": | |
| success = test_google() | |
| print(f"\n{'β Sucesso' if success else 'β Falhou'}") | |
| elif choice == "3": | |
| success = test_github() | |
| print(f"\n{'β Sucesso' if success else 'β Falhou'}") | |
| elif choice == "4": | |
| print("\nπ Testando mΓΊltiplos provedores...\n") | |
| # Descobrir quais provedores estΓ£o configurados | |
| available = list_available_providers() | |
| configured = [p for p, ok in available.items() if ok] | |
| if not configured: | |
| print("β Nenhum provedor configurado!") | |
| return True | |
| print(f"Provedores configurados: {', '.join(p.upper() for p in configured)}\n") | |
| results = {} | |
| for i, provider in enumerate(configured, 1): | |
| print("β" * 70) | |
| print(f"TESTE {i}/{len(configured)}: {provider.upper()}") | |
| print("β" * 70) | |
| results[provider] = test_provider(provider) | |
| if i < len(configured): | |
| print("\n") | |
| input(f"Pressione ENTER para continuar com {configured[i].upper()}...") | |
| print("\n" + "=" * 70) | |
| print(" π RESUMO FINAL") | |
| print("=" * 70) | |
| for provider, success in results.items(): | |
| status = "β Sucesso" if success else "β Falhou" | |
| print(f" {provider.capitalize():12s}: {status}") | |
| elif choice == "5": | |
| list_providers() | |
| elif choice == "6": | |
| show_env_guide() | |
| else: | |
| print("\nβ OpΓ§Γ£o invΓ‘lida. Tente novamente.") | |
| return True | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # MAIN | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| if __name__ == "__main__": | |
| try: | |
| # Carregar variΓ‘veis de ambiente | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| except ImportError: | |
| pass | |
| try: | |
| # Loop do menu | |
| while True: | |
| show_menu() | |
| if not main_menu(): | |
| break | |
| except KeyboardInterrupt: | |
| print("\n\nπ Cancelado pelo usuΓ‘rio") | |
| except Exception as e: | |
| print(f"\nβ Erro inesperado: {e}") | |
| import traceback | |
| traceback.print_exc() | |
Xet Storage Details
- Size:
- 26.7 kB
- Xet hash:
- 2e26e2475f62f1292d1ac81f777c594e84b53499c0d2fbde65f573da2743fefc
Β·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.