I am trying to use google oauth using ajax and jquery. I have no errors but when I click on login button, page refresh to current page. This makes me think, issue is with ajax. maybe I am missing a flag or field.
I want to go to google login page. and on success, i want to get user first name.
<script type="text/javascript">
$(document).ready(function () {
$('.LoginGoogleC').click(function () {
alert('start');
$.ajax({
type: 'POST',
url: "https://accounts.google.com/o/oauth2/token",
contentType: 'application/x-www-form-urlencoded; charset=utf-8',
crossDomain: true,
cache: true,
dataType: 'json',
data: {
client_id: '0000000-18911.apps.googleusercontent.com',
client_secret: 'fff-eee-fff',
redirect_uri: 'https://localhost:44329/LoginAPI.aspx',
grant_type: 'authorization_code'
},
success: function (data) {
alert('success' + data);
},
error: function (e) {
alert('error' + data);
}
});
alert('done');
});
});
</script>
I also tried using only jquery but still same thing. page refresh but no google oauth page
var clientID = '0000000-18911.apps.googleusercontent.com';
var redirectURL = 'https://localhost:44329/LoginAPI.aspx';
window.location.href = 'https//accounts.google.com/o/oauth2/v2/auth?' +
'scope=openid%20email' +
'&response_type=token' +
'&redirect_url=' + redirectURL +
'&client_id=' + clientID;
button - html
<asp:button ID="LoginGoogleB" CssClass="LoginGoogleC btn btn-lg center-block" runat="server"
Text="Login With Google" />