I
I
Igor Samokhin2015-08-08 17:13:33
JavaScript
Igor Samokhin, 2015-08-08 17:13:33

How to make authorization on the site through Odnoklassniki using js without reloading the site page?

Good afternoon,
I want to authorize through Odnoklassniki on the site, but I can’t reload the site page. VK has an open api for this, for example.
You can enter mamba.ru through classmates. Implemented with popup. I opened the popup via window. open with the address https://connect.ok.ru/oauth/authorize?client_id={c...
Now how can I tell the main page of my site from which the popup is opened that the token has been received and you can contact the classmates api to get the user id?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vjacheslav Kanivetc, 2015-08-10
@grigor007

In general, the general principle of such authorization is:
1. The application / site itself opens the OK authorization popup with the return url passed to a special page
2. This special page, in the presence of window.opener, makes a postMessage to this window with the event that the redirect has successfully occurred

document.addEventListener('DOMContentLoaded', function () {
        if (window.opener) {
            window.opener.postMessage('okAuthSucceded', 'some-params');
        }
    });

3. The original page received the message and knows that authorization has occurred
document.addEventListener('DOMContentLoaded', function () {
        window.addEventListener('message', function (event) {
            if (event.data == 'okAuthSucceded') { //todo
            }
        }, false);
    }, false);

I
Igor Samokhin, 2015-08-08
@grigor007

Now I am passing the parameters from the popup like this: window.opener.ok_params = document.location.href;
But maybe there are other ways?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question