| 1 | <?php |
| 2 | require __DIR__.'/lib/bootstrap.php'; |
| 3 | try { |
| 4 | $cfg=config(); |
| 5 | if (!$cfg['client_id'] || !$cfg['client_secret']) throw new RuntimeException('Production authentication needs a registered client ID and secret. See web/README.md.'); |
| 6 | $_SESSION['oauth_state']=bin2hex(random_bytes(32)); $_SESSION['oauth_started']=time(); |
| 7 | $game=$_GET['game']??''; |
| 8 | $_SESSION['return_game']=is_string($game)&&preg_match('/^[1-9][0-9]{0,14}$/D',$game)?$game:''; |
| 9 | $invite=$_GET['invite']??''; |
| 10 | $_SESSION['return_invite']=is_string($invite)&&preg_match('/^[a-f0-9]{48}$/D',$invite)?$invite:''; |
| 11 | header('Location: https://auth.timfalken.com/oauth/authorize?'.http_build_query(['client_id'=>$cfg['client_id'],'redirect_uri'=>baseUrl().'/callback.php','response_type'=>'code','state'=>$_SESSION['oauth_state']])); |
| 12 | } catch (Throwable $e) {http_response_code(503); echo htmlspecialchars($e->getMessage());} |
projects-timfalken-com microchess