gitment icon indicating copy to clipboard operation
gitment copied to clipboard

认证重定向错误

Open GeekaholicLin opened this issue 7 years ago • 31 comments

目测因为url中带有中文符号()导致认证出错。 比如在以下页面登录的时候出错:

http://blog.geekaholic.cn/2017/03/06/%E5%88%B6%E4%BD%9CHexo%E4%B8%BB%E9%A2%98%E8%AF%A6%E7%BB%86%E6%95%99%E7%A8%8B%EF%BC%882%EF%BC%89/

错误页面的url:

http://blog.geekaholic.cn/2017/03/06/%E5%88%B6%E4%BD%9CHexo%E4%B8%BB%E9%A2%98%E8%AF%A6%E7%BB%86%E6%95%99%E7%A8%8B(2)/?code=b95790c4c5be5d4322d6

控制台输出404:

/2017/03/06/%E5%88%B6%E4%BD%9CHexo%E4%B8%BB%E9%A2%98%E8%AF%A6%E7%BB%86%E6%95%99%E7%A8%8B(2)/?code=b95790c4c5be5d4322d6:1 GET http://blog.geekaholic.cn/2017/03/06/%E5%88%B6%E4%BD%9CHexo%E4%B8%BB%E9%A2%98%E8%AF%A6%E7%BB%86%E6%95%99%E7%A8%8B(2)/?code=b95790c4c5be5d4322d6 404 (Not Found)

而页面的id不是默认,自己设置的id: window.location.pathname,,主要是为了考虑以后的域名更换。 以上。

GeekaholicLin avatar May 01 '17 15:05 GeekaholicLin

error=redirect_uri_mismatch&error_description=The+redirect_uri+MUST+match+the+registered+callback+URL+for+this+application.

xiaohao890809 avatar May 12 '17 17:05 xiaohao890809

https://imsun.net/?error=redirect_uri_mismatch&error_description=The+redirect_uri+MUST+match+the+registered+callback+URL+for+this+application.&error_uri=https%3A%2F%2Fdeveloper.github.com%2Fv3%2Foauth%2F%23redirect-uri-mismatch @GeekaholicLin 如何解决的?

hifor avatar Jun 10 '17 09:06 hifor

@hifor 我暂时也没有解决。只能等作者来修复,或者你看源代码,或者避免使用中文的括号。

GeekaholicLin avatar Jun 11 '17 10:06 GeekaholicLin

@GeekaholicLin @hifor 我也是这问题,你们是如何解决的?

我的页面的id也是自己设置的id: window.location.pathname, Authorization callback URL我设置为http://shenshanlaoyuan.com 博客主页也是http://shenshanlaoyuan.com

文章下面评论点Login 登录跳转到首页,URL显示这样错误http://shenshanlaoyuan.com/?error=redirect_uri_mismatch&error_description=The+redirect_uri+MUST+match+the+registered+callback+URL+for+this+application.&error_uri=https%3A%2F%2Fdeveloper.github.com%2Fv3%2Foauth%2F%23redirect-uri-mismatch

shenshanlaoyuan avatar Jul 11 '17 13:07 shenshanlaoyuan

页面id不写也是上面的错误,求大神帮忙解决!非常感谢🙏

shenshanlaoyuan avatar Jul 11 '17 16:07 shenshanlaoyuan

@GeekaholicLin 同样发生了上述的问题,而且 Issue Page 这个链接是 Undefined

small-cat avatar Jul 12 '17 12:07 small-cat

@GeekaholicLin https://github.com/login/oauth/authorize?scope=public_repo&redirect_uri=http%3A%2F%2Fblog.wuzhenyu.com.cn%2F2016%2F12%2F22%2Fbuild-local-git-server.html&client_id=76da0403cb2661c20104&client_secret=c712b49de2c002d7572f2f9a583d174d1ec36a5b 这个是没有中文()的,仍然是错误链接

我看作者文章的login链接是 https://github.com/login/oauth/authorize?scope=public_repo&redirect_uri=https%3A%2F%2Fimsun.net%2Fposts%2Fgitment-introduction%2F&client_id=4ce2737289ce197769a1&client_secret=3731a9d6ff407355af912ea7a86dd0dd772ca84d

small-cat avatar Jul 12 '17 13:07 small-cat

我大概看了你们的问题,根据个人判断,和我的并不是同一个问题。虽然都是重定向错误。

你们的问题是匹配不成功,然后会重定向会你们设置的callback url,所以你们跳转后的url在你们的callback url 的基础上加上会一大串的报错参数信息。而我的是匹配成功,但是跳回的时候它改变了我原本的url,将中文的括号变成了英文的括号,所以我跳转到了一个404页面。

所以你们匹配不成功可以试试找找其他的出错点。

只有一个人 @small-cat 是提供了源地址的http://blog.wuzhenyu.com.cn/2016/12/22/build-local-git-server.html,初步看,很可能是你的初始化框没有初始化成功,而关于初始化评论的一些注意事项可以看看其他issues

GeekaholicLin avatar Jul 13 '17 03:07 GeekaholicLin

@shenshanlaoyuan 我的问题是看着官方文档理解错了,文档说明如下:

  1. 注册 OAuth Application

点击此处 来注册一个新的 OAuth Application。其他内容可以随意填写,但要确保填入正确的 callback URL(一般是评论页面对应的域名,如 https://imsun.net )。

然后我错把callback URL配置成 https://imsun.net ,这个是要配置成自己博客( http://hifor.net )的域名才对!

附上我的hexo相关配置

  • 主题的配置文件:
#评论插件
#gitment
gitment:
  owner: hifor
  repo: github-pages-comment
  client_id: 4ee****a32c
  client_secret: f9***016931d3
  • 模板文件:
<% if (!index && post.comments && theme.gitment){ %>
<section id="comments"></section>
<link rel="stylesheet" href="https://imsun.github.io/gitment/style/default.css">
<script src="https://imsun.github.io/gitment/dist/gitment.browser.js"></script>
<script>
    var labels = "blog,gitment";
    labels = labels.split(",");
    var gitment = new Gitment({
        id: window.location.pathname,
        owner: '<%- theme.gitment.owner %>',
        repo: '<%- theme.gitment.repo %>',
        oauth: {
            client_id: '<%- theme.gitment.client_id %>',
            client_secret: '<%- theme.gitment.client_secret %>'
        },
        labels: labels
    })
    gitment.render('comments');
</script>
<% } %>

hifor avatar Jul 14 '17 01:07 hifor

@hifor 谢谢,我的问题找到了。 我的是URL有空格,导致认证错误的。

shenshanlaoyuan avatar Jul 14 '17 02:07 shenshanlaoyuan

@shenshanlaoyuan 我看了一下你的博客评论,没有成功啊,仍然有 "Error: Comments Not Initialized" 这个错误,而且中路径下,Issue Page 也是 undefined

small-cat avatar Aug 09 '17 13:08 small-cat

@small-cat 没问题呀,别点上面链接,链接是错误的。你直接访问我博客http://shenshanlaoyuan.com/

shenshanlaoyuan avatar Aug 13 '17 01:08 shenshanlaoyuan

@shenshanlaoyuan 我可能是之前callback 地址有点问题,修改了认证,已经可以了,没有错误,但是我没有发现之前出的问题在哪,懵。

small-cat avatar Aug 15 '17 02:08 small-cat

要检查一下callback地址 如果是换了域名或者什么得换上你的域名

Yiaichen avatar Aug 21 '17 14:08 Yiaichen

@shenshanlaoyuan 和你之前一样的问题。检查url没有问题,也不知道为啥总是出现这个错误。。。。

drrui avatar Oct 13 '17 09:10 drrui

@xiaohao890809 这个问题真的是很多人都有啊,也不知道最后到底怎么解决

GeneralLi95 avatar Apr 10 '18 01:04 GeneralLi95

我也有这个问题,时好时坏。有时候登陆成功了但重定向到首页去了。 带上了这个错误: error=redirect_uri_mismatch&error_description=The redirect_uri MUST match the registered callback URL for this application.&error_uri=https://developer.github.com/apps/managing-oauth-apps/troubleshooting-authorization-request-errors/#redirect-uri-mismatch

shalldie avatar May 03 '18 10:05 shalldie

文章的链接里面有空格的,比如文章标题,虽然转换urlencode,所以要把标题的空格去掉啊!

iHTCboy avatar May 06 '18 13:05 iHTCboy

文章的链接里面有空格的不能用 这个问题希望修复一下

muzhi1991 avatar May 07 '18 13:05 muzhi1991

我的问题是用hexo博客生成的文章会把_post文件夹下面的文件名拿来作为url,url里面不能有中文的标点符号,否则在登录github账号后github pages服务器重定向会把中文的标点自动改为英文标点导致404错误,你也可以手动把重定向后的url里面的英文标点替换为原来的中文标点后重定向就成功了。所以还是在起文件名的时候避免使用中文标点为好,要想修正这个问题还需要在更正文件名后把github仓库里对应issue的第一条评论里面的url链接也替换为新的文章链接才可以

FireFour avatar May 14 '18 14:05 FireFour

不过我这样还是会在打开浏览器第一次login的时候出现 @shalldie 的问题,请问你最后解决了吗?

FireFour avatar May 16 '18 03:05 FireFour

@FireFour 避免使用中文标点空格,检查一下是不是空格引用?

iHTCboy avatar May 17 '18 03:05 iHTCboy

@iHTCboy 搞定啦,oauth里的callback url把https改成http就行了,第一次重定向的时候会自动把https改成http

FireFour avatar May 17 '18 04:05 FireFour

@FireFour 我的oauth里的callback url把https,Homepage URL也是https哦,没有问题啊 -。-

https://ihtcboy.com

iHTCboy avatar May 18 '18 01:05 iHTCboy

@iHTCboy 你清楚历史数据,然后关闭浏览器再开,再进博客登录,第一次Login可能会出现这个问题,logout后再重新login一般不会

FireFour avatar May 18 '18 01:05 FireFour

可能因为我网站的默认是http访问。。

FireFour avatar May 18 '18 01:05 FireFour

是的,所以总结一下: 文章链接避免使用 中文标点空格

另,callback url是https,Homepage URL也要是https

iHTCboy avatar May 18 '18 02:05 iHTCboy

@iHTCboy 我的没有中文和标点,还是有问题。 曾经成功过 蒙逼 了

fanux avatar May 25 '18 04:05 fanux

@fanux 还有callback url是https,Homepage URL也是https,如果是http,2个都一样,你检查看看?

iHTCboy avatar May 25 '18 05:05 iHTCboy

也出现了类似的问题。我的是callback 地址有问题。 解决方法(假如你已经正确映射了域名): 保证github pages的访问方式和gitment issue的访问方式一致,即都是http或者https image image

yanbinghu avatar Sep 05 '18 11:09 yanbinghu