Answer the question
In order to leave comments, you need to log in
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
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');
}
});
document.addEventListener('DOMContentLoaded', function () {
window.addEventListener('message', function (event) {
if (event.data == 'okAuthSucceded') { //todo
}
}, false);
}, false);
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 questionAsk a Question
731 491 924 answers to any question