Hello.
I recently created a website. I'm new to this and trying to learn php.
On my website where I want to make an authentication system with LFS API. But I'm getting a few errors.
First, there is a redirect to LFS, but the site does not ask for access to things such as username and user id. This example is in the photo.
The other thing I need to report is Username: Unknown
I get the Membership Date: Unknown error. This error is related to the first error I reported above.
What should I do? I couldn't find anything about this in the forum addresses. Thanks.
https://hizliresim.com/lwy0qfr
https://hizliresim.com/7wjs8k1
https://hizliresim.com/gtni887
I recently created a website. I'm new to this and trying to learn php.
On my website where I want to make an authentication system with LFS API. But I'm getting a few errors.
First, there is a redirect to LFS, but the site does not ask for access to things such as username and user id. This example is in the photo.
The other thing I need to report is Username: Unknown
I get the Membership Date: Unknown error. This error is related to the first error I reported above.
What should I do? I couldn't find anything about this in the forum addresses. Thanks.
https://hizliresim.com/lwy0qfr
https://hizliresim.com/7wjs8k1
https://hizliresim.com/gtni887
<?php
$client_id = "-";
$client_secret = "-";
$redirect_uri = "https://www.tutunculergaraj.com.tr/users.tr";
if (!isset($_GET['code'])) {
$scope = "identity.basic identity.lastupdate";
$authorization_url = "https://id.lfs.net/oauth2/authorize?client_id=$client_id&redirect_uri=$redirect_uri&response_type=code&scope=" . urlencode($scope);
header("Location: " . $authorization_url);
exit;
}
if (isset($_GET['code'])) {
$code = $_GET['code'];
$url = "https://id.lfs.net/oauth2/access_token";
$data = array(
'grant_type' => 'authorization_code',
'code' => $code,
'redirect_uri' => $redirect_uri,
'client_id' => $client_id,
'client_secret' => $client_secret,
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded'
));
$result = curl_exec($ch);
if (curl_errno($ch)) {
die('Erişim belirteci alınırken hata oluştu: ' . curl_error($ch));
}
curl_close($ch);
$response = json_decode($result);
if (isset($response->access_token)) {
$access_token = $response->access_token;
$user_info_url = "https://api.lfs.net/userinfo";
$ch = curl_init($user_info_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $access_token
));
$user_info_result = curl_exec($ch);
if (curl_errno($ch)) {
die('Kullanıcı bilgileri alınamadı: ' . curl_error($ch));
}
curl_close($ch);
$user_info = json_decode($user_info_result, true);
if ($user_info) {
// Kullanıcı bilgilerini değişkenlere atayın
$lfs_username = $user_info['username'] ?? "Bilinmiyor";
$membership_date = $user_info['membership_date'] ?? "Bilinmiyor";
echo "Kullanıcı adı: $lfs_username<br>";
echo "Üyelik Tarihi: $membership_date<br>";
// ve diğer bilgileri de ekleyebilirsiniz
} else {
die('Kullanıcı bilgileri alınamadı');
}
} else {
die('Access token alınamadı: ' . print_r($response, true));
}
} else {
die('Yetkilendirme kodu alınamadı');
}
?>