The online racing simulator
Help on authentication system with LFS api
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


<?php 
$client_id
= "-";
$client_secret = "-";
$redirect_uri = "https://www.tutunculergaraj.com.tr/users.tr";


if (!isset(
$_GET[&#039;code&#039;])) {
$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[&#039;code&#039;])) {
$code = $_GET[&#039;code&#039;];


$url = "https://id.lfs.net/oauth2/access_token";
$data = array(
&
#039;grant_type&#039; => &#039;authorization_code&#039;,
&#039;code&#039; => $code,
&#039;redirect_uri&#039; => $redirect_uri,
&#039;client_id&#039; => $client_id,
&#039;client_secret&#039; => $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(
&
#039;Content-Type: application/x-www-form-urlencoded&#039;
));
$result = curl_exec($ch);

if (
curl_errno($ch)) {
die(&
#039;Erişim belirteci alınırken hata oluştu: &#039; . 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(
&
#039;Authorization: Bearer &#039; . $access_token
));
$user_info_result = curl_exec($ch);

if (
curl_errno($ch)) {
die(&
#039;Kullanıcı bilgileri alınamadı: &#039; . 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[&#039;username&#039;] ?? "Bilinmiyor";

$membership_date = $user_info[&#039;membership_date&#039;] ?? "Bilinmiyor";


echo "Kullanıcı adı: $lfs_username<br>";
echo
"Üyelik Tarihi: $membership_date<br>";
// ve diğer bilgileri de ekleyebilirsiniz
} else {
die(&
#039;Kullanıcı bilgileri alınamadı&#039;);
}
} else {
die(&
#039;Access token alınamadı: &#039; . print_r($response, true));
}
} else {
die(&
#039;Yetkilendirme kodu alınamadı&#039;);
}
?>
Don't think those scope keys exists, althought, in fact, nobody knows which scopes do really exist in LFS API. However, you can try $scope="openid profile"; instead and it should yield the values you seek, I think.
Quote from CRAAACH :Don't think those scope keys exists, althought, in fact, nobody knows which scopes do really exist in LFS API. However, you can try $scope="openid profile"; instead and it should yield the values you seek, I think.

Thank you

FGED GREDG RDFGDR GSFDG