<?php
require_once __DIR__.'/../config/config.php';require_once __DIR__.'/../config/database.php';require_once __DIR__.'/../includes/functions.php';
$cfg=(require __DIR__.'/../config/oauth.php')['apple'];
if(!$cfg['client_id']||!$cfg['team_id']||!$cfg['key_id']||!is_file($cfg['private_key'])){setFlash('error','Login com Apple ainda não foi configurado no servidor.');header('Location: '.SITE_URL.'/auth/login.php');exit;}
$state=bin2hex(random_bytes(24));$nonce=bin2hex(random_bytes(24));$_SESSION['oauth_apple_state']=$state;$_SESSION['oauth_apple_nonce']=$nonce;
$params=['client_id'=>$cfg['client_id'],'redirect_uri'=>$cfg['redirect_uri'],'response_type'=>'code id_token','response_mode'=>'form_post','scope'=>'name email','state'=>$state,'nonce'=>$nonce];
header('Location: https://appleid.apple.com/auth/authorize?'.http_build_query($params));exit;
