无法从Docker容器打开URL

从Docker容器导航到Google身份validation页面时遇到问题。 该应用程序使用asp.net Core 2.0制作,目的是显示即将从Google Calendar API检索的事件,并根据需要创build事件。

当应用程序没有从Docker容器运行时,应用程序将按预期工作,生成授权代码请求URL,并基于环境(Windows,Linux或OSX)尝试使用OpenBrowser方法中的Process.start()打开URL。

private bool OpenBrowser(string url) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { url = System.Text.RegularExpressions.Regex.Replace(url, @"(\\*)" + "\"", @"$1$1\" + "\""); url = System.Text.RegularExpressions.Regex.Replace(url, @"(\\+)$", @"$1$1"); Process.Start(new ProcessStartInfo("cmd", $"/c start \"\" \"{url}\"") { CreateNoWindow = true }); return true; } if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { Process.Start("xdg-open", url); return true; } if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { Process.Start("open", url); return true; } return false; } 

当浏览器成功打开时,用户需要input他的Google帐户凭据并login才能接收用于创build令牌的授权码。

 public async Task<AuthorizationCodeResponseUrl> ReceiveCodeAsync(AuthorizationCodeRequestUrl url, CancellationToken taskCancellationToken) { var authorizationUrl = url.Build().AbsoluteUri; using (var listener = StartListener()) { bool browserOpenOk; try { browserOpenOk = OpenBrowser(authorizationUrl); } catch (Exception e) { Logger.Error(e, "Failed to launch browser with \"{0}\" for authorization", authorizationUrl); throw new NotSupportedException(String.Format("Failed to launch browser with \"{0}\" for authorization. See inner exception for details.", authorizationUrl, e)); } var ret = await GetResponseFromListener(listener, taskCancellationToken).ConfigureAwait(false); s_receivedCallback = true; return ret; } } 

我的猜测是,在Linuxdocker容器没有必要的工具来打开url,这是什么原因造成的问题。 我的问题是,有人可以告诉我如何转发的URL在主机上打开,而不是在容器内,或者我怎样才能得到令牌,而不是试图从docker容器打开url?

谷歌默认使用这种authentication用户的方式(通过打开URL与Process.start),也打开随机端口来侦听authentication响应代码,所以我不得不创build我自己的类实现ICodeReceiver,因为docker需要确切的端口在容器内运行图像之前指定。

Interesting Posts