Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# asp.net mvc中的Google身份验证-无法获取Google登录的重定向URL_C#_Asp.net Mvc_Asp.net Mvc 4_Redirect_Google Oauth - Fatal编程技术网

C# asp.net mvc中的Google身份验证-无法获取Google登录的重定向URL

C# asp.net mvc中的Google身份验证-无法获取Google登录的重定向URL,c#,asp.net-mvc,asp.net-mvc-4,redirect,google-oauth,C#,Asp.net Mvc,Asp.net Mvc 4,Redirect,Google Oauth,我在互联网上很少看到谷歌认证是通过WebAPI进行的 所以,我想在ASP.NET MVC Web应用程序中尝试类似的方法。我在如何获取我的应用程序的RealTurrI时遇到了麻烦。 1.应用程序在google中注册,clientid和secret在Authconfig.cs中提到 2.点击我的按钮后,我必须重定向到GoogleSignIn页面。将用户带到登录页面的重定向URL(authrequestUrl)是我没有得到的 在Web api中,请求下面的url(GET请求)将返回重定向url作为响

我在互联网上很少看到谷歌认证是通过WebAPI进行的

<>所以,我想在ASP.NET MVC Web应用程序中尝试类似的方法。我在如何获取我的应用程序的RealTurrI时遇到了麻烦。 1.应用程序在google中注册,clientid和secret在Authconfig.cs中提到

2.点击我的按钮后,我必须重定向到GoogleSignIn页面。将用户带到登录页面的重定向URL(authrequestUrl)是我没有得到的

在Web api中,请求下面的url(GET请求)将返回重定向url作为响应。

在我的登录视图中单击我的登录按钮后,我可以使用它将用户重定向到google登录页面

MyLogin.cshtml

<body>
    <row>
    <button id="GoogleBtn" type="button" class="col-md-5 btn">Google</button>
    </row>
</body>
<script type="text/javascript">
$document.ready(function ()
{
    $('#GoogleBtn').click(function ()
    {
        window.location.href="RedirectUrl"
    });
});
</script>
    <row>
         <button id="GoogleBtn" type="button" class="col-md-5 btn btn-danger" onclick="googleLogin()">Google</button>
    </row>

<script type="text/javascript">

   var OAUTHURL = 'https://accounts.google.com/o/oauth2/auth?';
   var VALIDURL = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=';
   var SCOPE = 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email';
   var CLIENTID = 'xxxxxxxxxxxmyclientidxxxxx.apps.googleusercontent.com';
   var REDIRECT = 'http://myapp.local/dashboard';
   var LOGOUT = 'http://myapp.local/logout';
   var TYPE = 'token';
   var _url = OAUTHURL + 'scope=' + SCOPE + '&client_id=' + CLIENTID + '&redirect_uri=' + REDIRECT + '&response_type=' + TYPE;

    function googleLogin()
    {
     window.location = _url;
    }

</script>

谷歌
$document.ready(函数()
{
$('#GoogleBtn')。单击(函数()
{
window.location.href=“重定向URL”
});
});
在Asp.net MVc中, 存在两个操作-外部登录和外部登录回调

调用外部登录- 将返回错误-“所需的防伪表单字段“\uu RequestVerificationToken”不存在。”

调用externallogincallback- 将重定向到另一个视图(~/Views/Account/Login),其中包含一个Google按钮。 单击该按钮后,我将进入谷歌登录页面,其中包含所有要处理和登录的请求参数

我希望我的应用程序直接重定向到谷歌登录页面,而无需进入帐户/登录视图,然后在单击谷歌按钮时重定向到登录页面

有人帮我获取mvc应用程序的重定向URL

更新:

Oauth请求url/Google登录请求url就是我所使用的 寻找,我被重定向URL弄糊涂了。我找到了一种方法 构建请求Url,我成功地使用 javascript


这段代码允许我向GoogleSignin页面发出Oauth请求

MyLogin.cshtml

<body>
    <row>
    <button id="GoogleBtn" type="button" class="col-md-5 btn">Google</button>
    </row>
</body>
<script type="text/javascript">
$document.ready(function ()
{
    $('#GoogleBtn').click(function ()
    {
        window.location.href="RedirectUrl"
    });
});
</script>
    <row>
         <button id="GoogleBtn" type="button" class="col-md-5 btn btn-danger" onclick="googleLogin()">Google</button>
    </row>

<script type="text/javascript">

   var OAUTHURL = 'https://accounts.google.com/o/oauth2/auth?';
   var VALIDURL = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=';
   var SCOPE = 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email';
   var CLIENTID = 'xxxxxxxxxxxmyclientidxxxxx.apps.googleusercontent.com';
   var REDIRECT = 'http://myapp.local/dashboard';
   var LOGOUT = 'http://myapp.local/logout';
   var TYPE = 'token';
   var _url = OAUTHURL + 'scope=' + SCOPE + '&client_id=' + CLIENTID + '&redirect_uri=' + REDIRECT + '&response_type=' + TYPE;

    function googleLogin()
    {
     window.location = _url;
    }

</script>

谷歌
var oauthull='1〕https://accounts.google.com/o/oauth2/auth?';
var VALIDURL=https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=';
var范围=https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email';
var CLIENTID='xxxxxxxxxx myclientidxxxxx.apps.googleusercontent.com';
var重定向http://myapp.local/dashboard';
var注销http://myapp.local/logout';
变量类型='token';
var_url=oauthull+'scope='+scope+'&client_id='+CLIENTID+'&redirect_uri='+redirect+'&response_type='+type;
函数googleLogin()
{
window.location=\uURL;
}

重定向URI是google将返回身份验证的页面。它是在Google开发者控制台中为您的凭据设置的。这不是你要的东西。谢谢你花时间回复。我实际上是想让RequestUrl执行对Google Signin的宣誓请求,我在整个问题中都提到了重定向URL。我只是想知道为什么你使用JavaScript而不是官方的Google。Net客户端库。