jquery-cordova-oauth2
jquery-cordova-oauth2 copied to clipboard
InApp Browser Not closing and returnig values
Hi there. And thank you for your nice library.
I am using this library implicit call for a custom service of mine.
The problem is that I cannot get it to close the inappbrowser.
I have even tried window.open('','_self').close(); or window.close(); after the authentication takes place but I get a
"Scripts may close only the windows that were opened by it."
Do you have any idea on how to close the inappbrowser and therefore fire the callback function of the oauth2?
Thank you!
have u added the InAppBrowser Cordova plugin? are u testing built app on device ?
I have the same issue, my code is (coffeeScript)
$.oauth2 {
auth_url: 'https://www.facebook.com/dialog/oauth'
response_type: 'token'
client_id: 'id'
redirect_uri: "myserver/user/token/"
other_params:
scope: 'email user_about_me public_profile'
display: 'popup'
}, ((token, response) ->
getUserFacebookInfo(token)
return
), (error, response) ->
console.log 'error',error,response
return
Actually I don't need the calllback url, because I do all the login on cordova app, I get the token in the success and after that y consult the user information in getUserFacebookInfo, the thing is after the redirect_uri go to my end point it return 'ok' and the InAppBrowser never close, i do have installed and updated the plugin.
Edit
I modified my endpoint of redirect_uri, now my server ends with res.end()
(nodeJs)
and I very sure that the oauth works because it call my endpoint, but the inappbrowser never close
Thanks
@camiloperezv what version of InAppBrowser are you using?
@krisrak my InAppBrowser is cordova-plugin-inappbrowser 1.0.1 "InAppBrowser"
and my cordova version is 5.4.0
Edit
I tried moving my project to localhost again, but the inappbrowser doesn't close
I tried everithing, changin my endpoint, changing the parameters in facebook app, nothing works for me, the browser never close after success login
I tried with Cordova 5.1.1 and InAppBrowser 1.1.0, it worked on ios9.2 iphone6 device, here is my test code, change google client_id
and redirect_uri
and try:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width" />
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="cordova.oauth2.js"></script>
<script>
function onDeviceReady(){
console.log("deviceready");
}
document.addEventListener("deviceready", onDeviceReady, false);
function google_login_client() {
$.oauth2({
auth_url: 'https://accounts.google.com/o/oauth2/auth',
response_type: 'token',
logout_url: 'https://accounts.google.com/logout',
client_id: '000000000000.apps.googleusercontent.com',
redirect_uri: 'http://www.initlabs.com/oauth2callback',
other_params: {scope: 'profile'}
}, function(token, response){
$("#logs").html("<p>access_token: "+token+"</p>");
$("#logs").append("<p>response: "+JSON.stringify(response)+"</p>");
}, function(error, response){
$("#logs").html("<p>error: "+JSON.stringify(error)+"</p>");
$("#logs").append("<p>response: "+JSON.stringify(response)+"</p>");
});
}
</script>
<title>Oauth2 Cordova XDK</title>
</head>
<body>
<h1>Oauth2</h1>
<hr>
<button onclick="google_login_client()">Google Login - client</button>
</body>
</html>
the redirect_uri
can be anything that, it can also be something that does not exist, (like it can return http 404)
I create a new app, I tried but i get this error, both Google and Facebook
Error: Syntax error, unrecognized expression: #access_token=VERYBIGTEXT&expires_in=NUMBER
Then it goes to my redirect uri
Hi everybody.
I found out that there is a problem on running under the "browser" device.
Specifically, the
var loginWindow = window.open(login_url, '_blank', 'location=no');
doesn't work. It works properly on Android, I will let you know soon what happens on IOS.
This is a problem only to the fact that it slows down development debuging.
But I don't understand @joomlaevolved, you are talking about my problem with the Error: Syntax error, unrecognized expression ??
I'm getting mad with this oauth! ! !
@camiloperezv: I am sorry, I was talking about the initial matter of the post.
I tested on my android, page is close. Most of the reason.
- Please do add white list
graph.facebook.com https://www.facebook.com/dialog/oauth https://accounts.google.com/o/oauth2/auth api.twitter.com