[英]Access token for Google Authentication
I have a ASP.NET MVC web application that uses Google Authentication. 我有一个使用Google身份验证的ASP.NET MVC Web应用程序。 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. 但是我试图找出如何在代码中获取登录的访问令牌,以便将其传递到我希望使用的Web API的标头中。
Here's how you can use Google's Sign-In button template to initialize the login & grant of permissions: 您可以使用以下方法使用Google的登录按钮模板来初始化登录和权限授予:
<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. 然后,您可以将idToken
(accessToken)传递给API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.