I m working with Omada Controller (External Portal Server). That is, to register users through the EAP. The device must be allowed to use WiFi. I use following documentation:
https://www.tp-link.com/ru/support/faq/3231/ I tested the requests through Postman. Everything is working. However, it is necessary to send a cookie in the request to authorize the device after logging in.
我在Laravel写道: 但是,没有储存或发送 co。
public function AuthFree(Request $req)
{
$inputs = $req->all();
//IP Address of Controller
$endPoint = https://CONTROLLER_API:PORT/CONTROLLER_ID/api/v2/hotspot/extPortal/auth ;
$operatorData = self::getCSRFToken();
$csrfToken = $operatorData->object()->result->token;
$cookies = $operatorData->cookies()->getCookieByName( TPEAP_SESSIONID )->toArray();//->getValue();
$deviceBody = [
clientMac => $inputs[ clientMac ],
apMac => $inputs[ apMac ],
ssidName => $inputs[ ssidName ],
radioId => $inputs[ radioId ],
time => 1859960742,
authType => 4,
];
$authDevice = Http::withCookies($cookies, $endPoint)
->timeout(30)->withOptions([
verify => false,
])
->withHeaders([
Content-Type => application/json ,
Accept => application/json ,
Csrf-Token => $csrfToken,
])
->post($endPoint, $deviceBody);
dd($authDevice);
}
//Login operator.
public function getCSRFToken()
{
$authOperator = Http::accept( application/json )->timeout(15)->withOptions([
verify => false,
])
->post( https://IP:PORT/ID/api/v2/hotspot/login , [
name => USERNAME ,
password => PASSWORD ,
]);
return $authOperator;
}
i 还写成以下法典:
$ch = curl_init();
// Set return to a value, not return to page
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Set up cookies.
curl_setopt($ch, CURLOPT_COOKIEJAR, request()->cookie( TPEAP_SESSIONID ));
curl_setopt($ch, CURLOPT_COOKIEFILE, request()->cookie( TPEAP_SESSIONID ));
// Allow Self Signed Certs
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
// API Call
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($authInfo));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$res = curl_exec($ch);
$resObj = json_decode($res);
return $resObj;
但这也会产生错误。
The operator enters the system and receives a token through the getCSRFToken
function mentioned above. A COOKIE is returned along with the token. I need to send TOKEN and COOKIES together to authorize the device.
Meanwhile, the getCSRFToken
function is running and returning tokens. But authDevice
is returning an error. Because it can t get Header and Cookies.
我的问题是:我如何拯救 co,我如何能够在请求中添加这些 co,并送它们?
我所写的法典有什么错误?