【问题标题】:Access token for Google AuthenticationGoogle 身份验证的访问令牌
【发布时间】:2017-04-29 09:05:53
【问题描述】:

我有一个使用 Google 身份验证的 ASP.NET MVC Web 应用程序。身份验证部分工作正常。但我正在尝试找出如何在我的代码中获取用于登录的访问令牌,以便我可以在我拥有并希望使用的 Web api 的标头中传递它。

【问题讨论】:

标签: c# asp.net-mvc google-authentication


【解决方案1】:

以下是使用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。

【讨论】:

    猜你喜欢
    • 2019-04-28
    • 1970-01-01
    • 1970-01-01
    • 2017-04-11
    • 2017-02-17
    • 2023-03-17
    • 2020-01-12
    • 2014-12-17
    • 2014-03-12
    相关资源
    最近更新 更多