|
I want to see notes on every device. The only way to do this is to store notes on the server , and teach the plugin to recognize the user. While on the VKontakte page , the user is already authorized ; it is enough to find out who exactly. For this, the VKMemos plugin uses the VKontakte API library. Authorization in the plugin is tied to VKontakte authorization. To use the VKontakte API, you need to create an application . Each application receives a secret key. When the plugin is launched for the first time, the user receives a VKontakte pop up window asking for permission. The user only needs to give consent without entering any data. At the same time, in the browser, the VKontakte library generates a hash code based on the user data and the application s secret key. Each request to the server is signed with this hash code.
The server checks requests for authenticity by recreating the hash code on its photo editing servies side and comparing it with the received one. To fake the code, you need to know the user data and the secret key , known only to the application developer. Data synchronization Notes are stored on the server and linked to the VKontakte user. To speed up the work of the plugin, when launched, it downloads all notes and later displays them not from the server , but locally. Notes are always saved to the server. If you have multiple tabs open , changing notes in one of them will save them to the server , but will not update notes from the server in other tabs. To synchronize the work of several tabs , notes are stored not in a local variable , but in the local storage common to the browser localstorage.

Changing a note in one tab triggers an event that other tabs receive , updating the note. However, the local storage change event does not work on VKontakte pages. During the study , it turned out that VKontakte intercepts these events for internal work. The local storage change event, according to the standard, is triggered in all other tabs except the one in which it was called. Apparently , VKontakte needed to receive this event in the original tab. To do this, they created a special iframe with an event interceptor and exchanged data through Message events. Two solutions were found replace their subscription with a copy with your own code added , or subscribe to the Message event.
|
|