OAuth Ajax Callback URL Design Logic
I'm designing a Google Contacts Import application using OAuth and PHP. I'm trying to figure how the initial request page can interact with my callback page.
Page Structure:
Page A: Callback page
Pa开发者_JS百科ge B: OAuth request page
Process:
User clicks "Import Contacts" on Page A, a new window(Page B) opens and directs to Google OAuth Login.
Page B contains script to exchange OAuth Token; once the Access was given, Page B pop up window closes and passes the access token to Page A
Page A uses Access Token acquired from Page B, pulls Google XML data, parses it, and refreshes through AJAX to display parsed contact information.
Right now, I'm only able to interact with the callback information in Page B, the popped up window. What I want to do is the pass information from Page B to Page A.
I'm sure this requires some sort of AJAX programming but could you tell me the general design logic to achieve this? No specific code required.
One way to communicate both pages would be to use a common storage place (database on server), and pull the data in both pages periodically with setInterval()
setInterval(function(){
//Your AJAX code to get data from common database here
}, 1000); //1000 will make a request each second
If you're opening the other window with window.open, another way would be to have global javascript functions (public by default) in both pages, and call them from the other page.
PageA
var pageB = window.open("pageB");
function receiveDataFromPageB(data){
//Do something with data
}
...
//This should be called when needed, for example to send the token
pageB.receiveDataFromPageA(some_data);
Page B
var pageA = window.opener;
function receiveDataFromPageA(data){
//Do something with data
}
...
//This should be called when needed, for example to send the token back
pageA.receiveDataFromPageB(some_data);
I think this will guide you to be able to intercommute between your pages. Hope this helps. Cheers
精彩评论