F
F
Forever Extreme2022-03-30 22:55:26
css
Forever Extreme, 2022-03-30 22:55:26

How to properly set up a redirect in a frame (VK authorization)?

Hello everybody!
Everything works for me, I just don’t like how it’s implemented, so I’m asking for advice here))
There is an application for bitrks24. It works in a frame. It has a couple of inputs (among others) for the community id in VK and access_token also for VK. To get this access_token, I need to first get some code , and then using this code to get an access_token . And write this access_token to the input from the frame (as mentioned at the beginning).
I'm using PHP SDK VK which is provided by VK itself. How it all works
The first file is getCode.php

$vk = new VK\Client\VKApiClient();
$code = $vk->getCode();
echo $code;

Then I form a link with this code and go to it. A tab will open. A VK window appears where they say you allow such an application the right to this and that. Click ok and access_token will be displayed . We copy it and paste it into the input from the beginning of the question)
File number 2 (which makes a request to get an access_token) getAccessToken.php
if (isset($_GET['code'])) {
    $oauth = new VK\OAuth\VKOAuth();
    $code = $_GET['code'];
    $response = $oauth->getAccessToken($code);
    $access_token = $response['access_token'];

?>
<?php
if (!empty($access_token)) {
?>
<div>
    <p>Ваш access_token</p>
</div>
<div>
    <p><?php echo $access_token ?></p>
</div>
<?php } ?>

I don't like this piece at the bottom. I don't like to cross html and php in one file. Is there a way to pass information from the getAccessToken.php file to a frame? I tried to open a frame in a frame, but Bitrix does not allow this for security reasons (type)
I tried to display the access_token not on the screen but in localStorage , but in fact it is the same.
Tell me, please, what is the best way to do it?)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Lebedev, 2016-07-28
@slavikse

I think in your simple case, it's better to use css :focus for this .
Here . If you are not familiar with technologies, click on the down arrow and there view compile.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question