hexo gitalk 报错 redirect_uri_mismatch

最近使用 gitalk 登录时候报错,跳转到设置的回调地址,并且带有这些参数 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%2Fapps%2Fmanaging-oauth-apps%2Ftroubleshooting-authorization-request-errors%2F%23redirect-uri-mismatch

各种百度,谷歌后,并没找到最好的解决办法,最后发现如下问题会导致上面报错:

  1. 文章的 Front-matter 的 permalink 字段包含空格。
  2. 当前登录页面链接中包含空格字符,也就是 encodeURIComponent 之后的 %20 字符。
  3. OAuth Apps 里面 Authorization callback URL 字段填写的域名跟当前登录页面的域名不相同,此处填写的域名可以不要端口,填写域名即可。

处理办法

新建一个 过滤器 用于处理空格。

新建文件 themes/${你的主题目录}/scripts/post_permalink.js

1
2
3
4
hexo.extend.filter.register('post_permalink', function(data){
// 多个空格处理为一个连字符
return data.replace(/\s+/g, '-');
});

以上的代码会将多余空格替换为连字符 -

本文由 linx(544819896@qq.com) 创作,采用 CC BY 4.0 CN协议 进行许可。 可自由转载、引用,但需署名作者且注明文章出处。本文链接为: https://blog.jijian.link/2020-01-17/hexo-gitalk-redirect_uri_mismatch/

如果您觉得文章不错,可以点击文章中的广告支持一下!