0
我有一個使用Google身份驗證的ASP.NET MVC Web應用程序。認證部分工作正常。但我試圖找出如何在代碼中獲取登錄的訪問令牌,以便我可以將它傳遞到頭端以供我使用並希望使用的Web API。Google身份驗證的訪問令牌
我有一個使用Google身份驗證的ASP.NET MVC Web應用程序。認證部分工作正常。但我試圖找出如何在代碼中獲取登錄的訪問令牌,以便我可以將它傳遞到頭端以供我使用並希望使用的Web API。Google身份驗證的訪問令牌
這裏是你如何使用Google's Sign-In button模板來初始化權限的登錄&批:
<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;
}
然後,您可以通過idToken
(的accessToken)到API。
您可以將訪問令牌保存到您的數據庫 – UJS
當然。但是,我怎樣才能獲得訪問令牌。 – avsln
按照以下鏈接,如果覺得任何問題將提供邏輯代碼: https://developers.google.com/+/web/api/rest/?hl=en_GB – UJS