angularjs - github 重定向_uri 与 angularjs

标签 angularjs router github-api

我正在尝试在我的应用程序中添加 github 登录。因此,在本地计算机上进行测试时,我将回调网址设置为 http://localhost:8000/login/callback/ .

之后,我向我的页面添加一个登录链接,如下所示:<a href="https://github.com/login/oauth/authorize?client_id=CLIENT_ID&scope=user&redirect_uri=http://localhost:8000/login/callback">Login</a> ,还有

$routeProvider.when('/login/callback', {
  controller: 'loginCtrl'
});

它成功返回给我一个带有如下链接的代码:http://localhost:8000/login/callback?code=cd07ff3b70f5d1d1b8a2 。但是angularjs无法正确响应。

Error response

Error code 404.

Message: File not found.

Error code explanation: 404 = Nothing matches the given URI.

我还尝试将我的redirect_url设置为http://localhost:8000/#/login/callback ,但是返回链接是这样的 http://localhost:8000/?code=61e9c8b73c073a0bccc0/#/login/callback

我需要代码出现在网址末尾而不是中间,以便我可以使用 $location.search().code获取我的代码。如何正确设置?

想更改我的redirect_uri 或更改我的路由器吗?

最佳答案

@lowerkey 我仍然不知道如何处理这个问题,但我认为这是因为页面被重新加载

当您未将 html5Mode 设置为 true 时,网址处将为 #,如果您重新加载页面,则# 会将信息跟踪到 $scope 以与 htmlHistory api 配合使用,以便应用程序即使在页面刷新时也能正常工作。

但是一旦将 html5Mode 设置为 true,就没有 # 来存储任何 $scope 信息,当页面重新加载时,Angular无法找到相应的范围,因此返回404

您可以查看$location section on angularjs guide ,它有一个部分解释了为什么会发生这种情况。

Page reload navigation

The $location service allows you to change only the URL; it does not allow you to reload the page. When you need to change the URL and reload the page or navigate to a different page, please use a lower level API, $window.location.href.

关于angularjs - github 重定向_uri 与 angularjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17509413/

相关文章:

javascript - 在 AngularJs 中对点击事件应用指令

linux - 通过外部 IP 地址或 DynDNS url 查看设备内网页面

github - 使用GitHub list-issues-for-repository API

git - 在克隆 GitHub 存储库之前如何查看其大小?

Javascript - 如何在点击时禁用这些星星的颜色变化?

javascript - 您如何处理带有请求 promise 的 cookie?

javascript - 为什么 AngularJS "$http.get().then(...)"适用于纯文本文件,但不适用于 JSON 文件?

javascript - 如何访问 reducer (redux-router)中的当前位置?

python - Flask - 如何通过路由器使应用程序在外部可见?

github - Github Graphql筛选器里程碑问题