2012-06-12 11 views
18

buena foto por Tim Rosenberg que muestra exactamente cómo OAuth2 la obra de:fusiontables mesa privada con OAuth2

enter image description here

Soy una especie de un perezoso para siquiera empezar a buscar en este 2files y test así que busqué para easyest manera de

1.get símbolo

2.Acceso con esa señal

con ayuda de gwt-oauth2

lo puso en la cabeza index.php: <script type="text/javascript" src="gwt-oauth2.js"></script>

y esto a su cuerpo

<script type="text/javascript"> 
(function() { 
var GOOGLE_AUTH_URL = "https://accounts.google.com/o/oauth2/auth"; 
var GOOGLE_CLIENT_ID = "CLIENT_ID"; 
//var PLUS_ME_SCOPE = "https://www.googleapis.com/auth/plus.me"; 
//var FusionTable_SCOPE = "https://www.googleapis.com/auth/fusiontables";  
var button = document.createElement("button"); 
button.innerText = "Authenticate with Google"; 
button.onclick = function() { 

var req = { 
    'authUrl' : GOOGLE_AUTH_URL, 
    'clientId' : GOOGLE_CLIENT_ID, 
    'scopes': ['https://www.googleapis.com/auth/plus.me', 
       'https://www.googleapis.com/auth/fusiontables' 
       ], 
}; 

oauth2.login(req, function(token) { 
    alert('Got an OAuth token:\n'+ token +'\n'+ 'Token expires in '+ oauth2.expiresIn(req) +' ms\n'); 
    }, function(error) { 
    alert("Error:\n" + error); 
    }); 
}; 

var dv = document.getElementById('admin-content'); 
dv.appendChild(button); 
var clearTokens = document.createElement('button'); 
clearTokens.innerText = 'Clear all tokens' 
clearTokens.onclick = oauth2.clearAllTokens; 
dv.appendChild(clearTokens); 
})(); 
</script> 

OK,

Ahora se puede ver la conexión y la redirección de oauthWindow.html en una nueva ventana sin errores. Los parámetros GET ahora le muestran access_tokentoken_typeexpires_in. Compruebe el señal_acceso HERE

Como se ve señal_acceso trabajo genial, pero

Lo que todavía no lo consigue es primera alerta de que:

oauth2.login(req, function(token) { 
    alert('Got an OAuth token:\n' + token + '\n' 
    + 'Token expires in ' + oauth2.expiresIn(req) + ' ms\n'); 
}, function(error) { 
    alert("Error:\n" + error); 
}); 

segunda alerta funciona bien y cuando intenta autenticación. oauthWindow.html de nuevo si todavía abierto que muestra una alerta de error (por lo que está funcionando!) Ahora vamos a añadir ese pequeño código para oauthWindow.html

<!DOCTYPE html> 
<html> 
    <head> 
    <script type="text/javascript"> 
     if (window.opener && window.opener.oauth2 && window.opener.oauth2.__doLogin) { 
     window.opener.oauth2.__doLogin(location.hash); 
     } else { 
     document.body.innerText = "Your browser seems to be stopping this window from communicating with the main window."; 
     } 
    </script> 
    </head> 
    <body></body> 
</html> 

perfecto!

Ahora, si quiere trabajar con tablas privadas, todo lo que necesita es agregar access_token a la url.

¡Gracias por darme la razón para contestarme!

+0

Gracias señor. Muchas gracias. – efwjames

+6

¿por qué eliminaste la respuesta? Deberías recuperarlo y luego hacer clic en el botón Aceptar. Eso debería ayudar a los usuarios que buscan una solución similar. –

+0

@Joseph Marikle mi error. resuelto – qpaycm

Respuesta

1

poner esto en oauthWindow.html archivo

<!DOCTYPE html> 
<html> 
    <head> 
    <script type="text/javascript"> 
     if (window.opener && window.opener.oauth2 && window.opener.oauth2.__doLogin) { 
     window.opener.oauth2.__doLogin(location.hash); 
     } else { 
     document.body.innerText = "Your browser seems to be stopping this window from communicating with the main window."; 
     } 
    </script> 
    </head> 
    <body></body> 
</html>