簡體   English   中英

部署到天藍色的Google身份驗證不起作用

[英]Google authentication not working when deployed to azure

我正在使用Google進行身份驗證。 下面的代碼在本地運行時工作正常,而在將其部署到Azure時拋出錯誤:

 HttpWebRequest webRequest = 
(HttpWebRequest)WebRequest.Create("https://accounts.google.com/o/oauth2/token");
                    webRequest.Method = "POST";
                    Parameters = "code=" + code + "&client_id=" + googleplus_client_id + "&client_secret=" + googleplus_client_secret + "&redirect_uri=" + googleplus_redirect_url + "&grant_type=authorization_code";
                    byte[] byteArray = Encoding.UTF8.GetBytes(Parameters);
                    webRequest.ContentType = "application/x-www-form-urlencoded";
                    webRequest.ContentLength = byteArray.Length;
                    Stream postStream = webRequest.GetRequestStream();
                    postStream.Write(byteArray, 0, byteArray.Length);
                    postStream.Close();
                    WebResponse response = webRequest.GetResponse();//**Error Occurs here**

我也試過

var values = new NameValueCollection();
var resp = client.UploadValues("https://accounts.google.com/o/oauth2/token?" + Parameters, values );
var responseString = Encoding.Default.GetString(resp);
serStatus = JsonConvert.DeserializeObject<GooglePlusAccessToken>(responseString);

再次在本地工作,但是當我將其部署為天藍色時,它不起作用

重定向網址如下所示:

https://sample.com/Home/User?code=4/uQB37PKUFlID8dSLFFTsYLEDdHWWOprWaMtpa6YasdxxxxxxxxxxH8OQVxg3UZMoDc&scope=email%20profile%20https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/userinfo.email

我收到以下錯誤消息和堆棧跟蹤 在此處輸入圖片說明

[WebException:遠程服務器返回錯誤:(400)錯誤的請求。] System.Net.HttpWebRequest.GetResponse()+1399
C:\\ CodePath \\ Controllers \\ HomeController.cs中的SomeSln.Controllers.HomeController.User():63 lambda_method(Closure,ControllerBase,Object [])+62
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase控制器,Object []參數)+14
System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext,IDictionary2參數)+169
System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext,ActionDescriptor actionDescriptor,IDictionary`2參數)+27
System.Web.Mvc.Async.AsyncControllerActionInvoker.b__39(IAsyncResult asyncResult,ActionInvocation innerInvokeState)+22
System.Web.Mvc.Async.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult)+29
System.Web.Mvc.Async.WrappedAsyncResultBase1.End()+49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)+32
System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3d()+50 System.Web.Mvc.Async。<> c__DisplayClass46.b__3f()+228 System.Web.Mvc.Async。<> c__DisplayClass33.b__32(IAsyncResult asyncResult)+ 10
System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult)+10
System.Web.Mvc.Async.WrappedAsyncResultBase1.End()+49
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)+34

它可能與重定向URL不在Google方面的批准列表中有關,而在localhost運行時使用的localhost則與重定向URL有關。

有關更多信息,請查看OAuth 2.0 >> Web應用程序(ASP.NET MVC)

希望能幫助到你!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM