Search This Blog

JavaScript Function -For Google oAuth for login with google plus

Hello guys,

I have another code for authenticate user using google oAuth, and using google developer to get the application Id.

Login with Google Plus OAuth.

Step 1

Add or register your domain at click here.

Importing GMail Contacts Google OAuth Connect with PHP.

Step 2

Verify your domain ownership with HTML file upload or including META tag.

Importing GMail Contacts Google OAuth Connect with PHP.

Step 3

Google will provide you OAuth consumer key and OAuth consumer secret key. 
Importing GMail Contacts Google OAuth Connect with PHP. 

Step 4

Create client ID OAuth Console here.  

Login with Google Plus Oauth

Step 5

Create client ID.

Login with Google Plus OAuth.

Step 6

Here the application OAuth client ID and client secret.

Login with Google Plus OAuth. 
 //here we have java script code

<script >
          var loc =;
          var OAUTHURL = '';

          var VALIDURL = '';

          var SCOPE = '';

//here you can use your own client Id that earlier you registered
          var CLIENTID = '*****************************';

          var REDIRECT = 'http://' + loc + '/edLoginpage.aspx';

          //var LOGOUT = '';

          var TYPE = 'token';

          var _url = OAUTHURL + 'scope=' + SCOPE + '&client_id=' + CLIENTID + '&redirect_uri=' + REDIRECT + '&response_type=' + TYPE;

          var acToken;

          var tokenType;

          var expiresIn;

          var user;

          var loggedIn = false;
//call this function onclick event of button in html
          function login() {
              var win =, "windowname1", 'width=800, height=600');
              var pollTimer = window.setInterval(function () {
                  try {
                      if (win.document.URL.indexOf(REDIRECT) != -1) {

                          var url = win.document.URL;
                          acToken = gup(url, 'access_token');

                  } catch (e) {


              }, 500);


          function validateToken(token) {


                  url: VALIDURL + token,

                  data: null,

                  success: function (responseText) {

                      loggedIn = true;

                  dataType: "jsonp"


          function gup(url, name) {

              name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");

              var regexS = "[\\#&]" + name + "=([^&#]*)";

              var regex = new RegExp(regexS);

              var results = regex.exec(url);

              if (results == null)

                  return "";


                  return results[1];

          function getUserInfo() {


                  url: '' + acToken,
                  data: null,
                  success: function (resp) {
                      user = resp;
                      var name =;
                      var r = splitUsername(name);
                      var SNfirstName = r.firstName;
                      var SNlastName = r.lastName;
                      var SNuserId =;
                      var SNuserEmail =;
                      var args = {
                          "SNfirstName": SNfirstName, "SNuserId": SNuserId, "SNlastName": SNlastName, "SNuserEmail": SNuserEmail

//use this information for manipulate for login or store this information in db


                  dataType: "jsonp"



//html code for button
you can use this button for login google plus

<a href="javascript:void(0);" class="btn btn-danger btn-circle"><i class="fa fa-google-plus fa-2x" onclick="login();"></i></a>

Bhupinder Singh

I am an Computer Science and Engineering Graduate working in the field of software developing for 5 years. I like programming, web developing. Freelance Programming and writing are my hobbies.

Post A Comment
  • Blogger Comment using Blogger
  • Facebook Comment using Facebook
  • Disqus Comment using Disqus

No comments :

Great! You've decided to leave a comment! Please bear in mind that comments are often moderated and that rel="nofollow" is in use and spammy comments will be deleted. Let's have a meaningful conversation instead. Thanks for stopping by!