H
H
hooligan3772019-04-23 15:44:34
PHP
hooligan377, 2019-04-23 15:44:34

Authorization classmates?

I do authorization through classmates and it seems everything is not as easy there as it was with Vkontakte.

// Параметры приложения
$OAuth_OK = ['uid' => '123456789', 'key' => 'PUBKEY', 'secret' => 'SECRETKEY', 'redirect' => 'http://yadro/sign-ok',];

// Формируем ссылку для авторизации
$okparams = array(
    'client_id'     => $OAuth_OK['uid'],
    'scope'         => 'VALUABLE_ACCESS,LONG_ACCESS_TOKEN,GET_EMAIL',
    'response_type' => 'token',
    'redirect_uri'  => $OAuth_OK['redirect']
);

// Получаем ссылку
echo '<a href="https://connect.ok.ru/oauth/authorize?'.urldecode(http_build_query($okparams)).'">Одноклассники</a>';

If VKontakte receives a code in the response and then we work with it, getting a token, etc., then we immediately get everything ....
// После успешной авторизации получаем code
if(isset($_GET['code'])){
  
  $params = array(
    'client_id'     => $clientId,
    'client_secret' => $clientSecret,
    'code'          => $_GET['code'],
    'redirect_uri'  => $redirectUri
);

$content = file_get_contents('https://oauth.vk.com/access_token?' . urldecodehttp_build_query($params)));

$response = json_decode($content);
 
 
$token = $response -> access_token; // Токен
$expiresIn = $response -> expires_in; // Время жизни токена
$userId = $response -> user_id; // ID  пользователя
$email = $response -> email; // EMAIL пользователя
 
  
$_SESSION['vkuid'] = $userId;
$_SESSION['token'] = $token;
$_SESSION['email'] = $email;

}

In response from ok.ru I get something like this:
access_token=gdfsgdfsgsdfgsfg&session_secret_key=dsffasfasfa&expires_in=1800

and I don't understand how to work with this further ... It's
very interesting to see examples in php, since it is not in the official documentation. Can you tell me how to proceed further? With Curl or can it be the same as with VK?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Popov, 2019-04-23
@be_a_dancer

For example, there are on the Internet. This is the first random example.

A
Alexander Aksentiev, 2019-04-24
@Sanasol

figured out in principle, there was only one question left:
I get a response of this type:
localhost/ok.php#access_token=1234567890&session_secret_key=1234567890&expires_in=1800
and I need to get:
localhost/ok.php?access_token=1234567890&session_secret_key=1234567890&expires_in=1800
? )))
---
With the first option, I naturally have no data, and with the second everything works, but changing every time during authorization is nonsense.

You are trying to get a client authorization token , but use it as a server one .
If I remember correctly, the catch is that LONG_ACCESS_TOKEN does not give servers or any other rights for some api methods.
So this is solved only by a headless browser, or get a token on the front through JS.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question