R
R
Roman Yamchuk2018-08-20 12:05:46
JavaScript
Roman Yamchuk, 2018-08-20 12:05:46

How to get data from a child window when redirecting?

To authorize oauth in my vuejs application, I open a child window, for example:

let vk_window = window.open(endpoint)
let redirect_uri = new RegExp(auth.settings.redirect_uri)
let watch_timer = setInterval(() => {
  try {
    let vk_location = vk_window.location
    if (redirect_uri.test(vk_location)) {
      clearInterval(watch_timer)
      let data = vk_window.location.hash.substring(1).split('&')
      //парсим data
      //устанавливаем токен
      //аутентифицируем

      vk_window.close()
    }
  } catch (error) {
    throw error
  }
}, 500)

But in this case, the error Uncaught DOMException: Blocked a frame with origin " localhost:8080 " from accessing a cross-origin frame is thrown in the console of the parent window.
Is there an alternative solution that doesn't reload the parent window?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Belyaev, 2018-08-20
@tomgif

There is a redirect uri parameter in the vk-App settings - you need to return html from it with a script that sends authorization data to the parent window via postMessage

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question