6

Need to make auth request in js but the browser does not support popups. Is there any way to redirect to a new url or show the request in the in html5 page of the application

250
  • 581
  • 5
  • 17

1 Answers1

1

By using this code check if user authorized your app

gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true}, callbackAuthResult);

Note: immediate:true if you set immediate true then it wont show popup.

You see? You don't open the popup, and manage the stuff in the callback. This callback is usually used for post-processes. Here we use it for authenticating.

in callbackAuthResult:

callbackAuthResult = function (authResult) {
    var authorizeButton = document.getElementById('authorize-button');
    if (authResult && !authResult.error) {
        authorizeButton.style.display = 'none';

    // do your processing here

    } else {
    authorizeButton.style.display = 'block';
    authorizeButton.onclick = callbackAuthClick;
    }
}

callbackAuthClick = function (event) {
gapi.auth.authorize({
    client_id: clientId,
    scope: scopes,
    immediate: false
}, handleAuthResult);
    return false;
}
simeg
  • 1,889
  • 2
  • 26
  • 34
3pic
  • 1,188
  • 8
  • 26
  • How will this give the accept and cancel option without popup? – 250 Jul 08 '15 at 13:18
  • @SumitBhatia are you kidding ? It's up to you to make this in a Html form, Sumit. You dont want the Google popup ? ok, but you have to implement the oauth request => google search. Then you send data to the google auth api and get a result. – 3pic Jul 08 '15 at 13:33
  • Well, you cannot have the both sides of the game. Clients like popup cause they know their data is not given to your website. If you kill popup, you have to get data and request API to know if datas are right or wrong. Hey, there is no magic. Read: https://developers.google.com/api-client-library/javascript/reference/referencedocs – 3pic Jul 08 '15 at 13:34