I have a ASP.NET MVC web application that uses Google Authentication. The authentication part is working fine. But I am trying to find out how I can get hold of the access token for the login in my code so that I can pass it in the header for a web api that I have and wish to consume.
0
votes
1 Answers
0
votes
Here's how you can use Google's Sign-In button template to initialize the login & grant of permissions:
<meta name="google-signin-client_id" content="{{ OAUTH2_CLIENT_ID }}">
<script src="https://apis.google.com/js/platform.js?onload=onLoad" async defer></script>
<div id="google-signin-button"
class="g-signin2"
data-width="170"
data-height="30"
data-onsuccess="onSignIn"
data-onfailure="onSignInFailure">
</div>
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
var idToken = googleUser.getAuthResponse().id_token;
}
You can then pass the idToken (accessToken) to an API.