$_ENV['DISCORD_CLIENT_ID'], 'redirect_uri' => static::DISCORD_REDIRECT_URI, 'response_type' => 'code', 'scope' => 'identify', ]); return "https://discord.com/api/oauth2/authorize?$query_string"; } public static function getTokenByCode(string $code): ?Token { $payload = json_decode(file_get_contents('https://discord.com/api/oauth2/token', false, stream_context_create([ 'http' => [ 'method' => 'POST', 'header' => 'Content-Type: application/x-www-form-urlencoded', 'content' => http_build_query([ 'client_id' => $_ENV['DISCORD_CLIENT_ID'], 'client_secret' => $_ENV['DISCORD_CLIENT_SECRET'], 'grant_type' => 'authorization_code', 'code' => $code, 'redirect_uri' => static::DISCORD_REDIRECT_URI, ]), ], ]))); if ($payload === null) return null; return new Token($payload); } public static function getMe(Token $getU): ?Me { return new Me(json_decode(file_get_contents('https://discord.com/api/oauth2/@me', false, stream_context_create([ 'http' => [ 'method' => 'GET', 'header' => "Authorization: Bearer $getU->access_token", ], ])))); } }