Encoding::UndefinedConversionError using Omniauth in Gitlab 13.5.3 with Laravel Passport - macOS 上的本
Posted
技术标签:
【中文标题】Encoding::UndefinedConversionError using Omniauth in Gitlab 13.5.3 with Laravel Passport - macOS 上的本地开发与 Docker【英文标题】:Encoding::UndefinedConversionError using Omniauth in Gitlab 13.5.3 with Laravel Passport - local dev on macOS with Docker 【发布时间】:2021-04-01 14:46:09 【问题描述】:现在有点茫然,下一步该去哪里解决这个问题。有人会对我可能会看什么或尝试让它工作有什么建议吗?如果需要,很乐意提供更多信息。
概述:
macOS Catalina 上的本地设置 oauth(客户端)GitLab 13.6.2 在 Docker 的 10080 端口上运行 GitLab 正在使用omniauth 1.8 oauth (server) Laravel 8 Passport 在 macOS 上使用 Laravel Valet 和 nginx 运行 通过本地 Laravel 站点和 oauth 流程测试的 Passport 完美运行 在 Gitlab 中,使用基于omniauth-gitlab 1.0.2 (https://github.com/linchus/omniauth-gitlab) 的自定义omniauth gem 进行单点登录 /omniauth-site/lib/omniauth/strategies/site.rb 是require 'omniauth-oauth2'
module OmniAuth
module Strategies
class Site < OmniAuth::Strategies::OAuth2
option :client_options,
site: 'http://testaccounts.test',
authorize_url: '/oauth/authorize',
token_url: '/oauth/token'
option :redirect_url
uid raw_info['id'].to_s
info do
email: raw_info['email'],
name: raw_info['name'],
nickname: raw_info['username'],
image: raw_info['avatar_url']
end
extra do
raw_info: raw_info
end
def raw_info
@raw_info ||= access_token.get('/api/v3/user').parsed
end
private
def callback_url
options.redirect_url || (full_host + script_name + callback_path)
end
end
end
end
我已尝试将.to_s.encode('UTF-8', invalid: :replace, undef: :replace, replace: '?')
添加到每个作业的电子邮件、姓名、昵称和图像以及uid。
从 GitLab 到我的 Laravel Passport 网站的流程似乎很好:
在 GitLab 上,单击“使用按钮签名” 授权或取消按钮,点击授权 返回GitLab与此URL:http://本地主机:10080 /用户/ AUTH /站点/回调代码= def502005f52682329fdfb5e3554b245f48743a8494a4f37e55258e999961fc3db07815df6922142837de6036e810b4303c22cc3c147dc5307581ffebd65d0df5cc7968896b1b0d184f4db3dbbdfa20375f66b35a6c30b95f842685cce15b56dba795db29011f54b00396f395bb6f51ced3630a82ba18ec8ebf0760d9cb8b75088b6d3f41d39a1343a17c6ab81ecfac99819dde1c107a0c73c994770d4266819f3cadc47d12902121739d108a348cba521f0824f33ce066adf88c777f9049313b4ea1a720759f1fd447c4c66c9b6fd8c03242b56efa1c6ddc1ff33ea65f77aefa8f3f311fc7b7690a03da3c7de196f076373684f3f54b57ab004d2eb947a5e101421fb7de7fa1b224b1cff63147c7fb15717dd18c30deb448d8e07486d3582d7842104d57a6c9d3a5986760779ebe75bef9e9df9e10792ff7546828a1cf8a29b126ffe3dca181931cfab85cfe2d65df3efa8458ca763785532b99b41614f5490a2ceb7dab46dad02f2027be9ab75092b52c0710520ec74f22cdacf923a163a16fd62d13d8442d5b97cb6566832a4e8908112aaf905c4&状态= 1f35df7bd654ca9c7786f83c7d4aec797ba9871746f8d3bc LI> 页面显示“500 糟糕,我们这边出了点问题。” 在 GitLab 中,gitlab-workhorse 日志显示:localhost:10080 127.0.0.1 - - [2020/12/23:01:38:13 +0530] "GET /users/auth/site/callback?code=def502005f52682329fdfb5e3554b245f48743a8494a4f37e55258e999961fc3db07815df6922142837de6036e810b4303c22cc3c147dc5307581ffebd65d0df5cc7968896b1b0d184f4db3dbbdfa20375f66b35a6c30b95f842685cce15b56dba795db29011f54b00396f395bb6f51ced3630a82ba18ec8ebf0760d9cb8b75088b6d3f41d39a1343a17c6ab81ecfac99819dde1c107a0c73c994770d4266819f3cadc47d12902121739d108a348cba521f0824f33ce066adf88c777f9049313b4ea1a720759f1fd447c4c66c9b6fd8c03242b56efa1c6ddc1ff33ea65f77aefa8f3f311fc7b7690a03da3c7de196f076373684f3f54b57ab004d2eb947a5e101421fb7de7fa1b224b1cff63147c7fb15717dd18c30deb448d8e07486d3582d7842104d57a6c9d3a5986760779ebe75bef9e9df9e10792ff7546828a1cf8a29b126ffe3dca181931cfab85cfe2d65df3efa8458ca763785532b99b41614f5490a2ceb7dab46dad02f2027be9ab75092b52c0710520ec74f22cdacf923a163a16fd62d13d8442d5b97cb6566832a4e8908112aaf905c4&state=1f35df7bd654ca9c7786f83c7d4aec797ba9871746f8d3bc HTTP/1.1" 500 2926 "http://localhost:10080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:84.0) Gecko/20100101 Firefox/84.0" 462
在 GitLab 中,production.log 显示:
Completed 200 OK in 1ms (ActiveRecord: 0.0ms | Elasticsearch: 0.0ms | Allocations: 112)
Started GET "/users/auth/site/callback?code=[FILTERED]&state=1f663e1c64bb8d7c359a627e52c109922e85d9aad356ccb0" for 172.20.0.1 at 2020-12-23 01:40:31 +0530
Encoding::UndefinedConversionError ("\xE2" from ASCII-8BIT to UTF-8):
lib/gitlab/omniauth_logging/json_formatter.rb:9:in `call'
config/initializers_before_autoloader/100_patch_omniauth_oauth2.rb:11:in `callback_phase'
lib/gitlab/request_profiler/middleware.rb:17:in `call'
lib/gitlab/jira/middleware.rb:19:in `call'
lib/gitlab/middleware/go.rb:20:in `call'
lib/gitlab/etag_caching/middleware.rb:13:in `call'
lib/gitlab/middleware/multipart.rb:234:in `call'
lib/gitlab/middleware/handle_null_bytes.rb:19:in `call'
lib/gitlab/middleware/read_only/controller.rb:51:in `call'
lib/gitlab/middleware/read_only.rb:18:in `call'
lib/gitlab/middleware/same_site_cookies.rb:27:in `call'
lib/gitlab/middleware/basic_health_check.rb:25:in `call'
lib/gitlab/middleware/handle_ip_spoof_attack_error.rb:25:in `call'
lib/gitlab/middleware/request_context.rb:23:in `call'
config/initializers/fix_local_cache_middleware.rb:9:in `call'
lib/gitlab/metrics/requests_rack_middleware.rb:49:in `call'
lib/gitlab/middleware/release_env.rb:12:in `call'
【问题讨论】:
【参考方案1】:这是与回调没有直接关系的那些狡猾的小 oauth2 错误之一。客户端在成功授权后已经在尝试获取用户数据。 /api/user 路由中有一个错误,修复后解决了上述问题。
根据我昨晚阅读的内容,错误似乎是由于提供了 html 页面而不是客户端在访问 /api/user 时期望看到的 JSON 数据。
【讨论】:
以上是关于Encoding::UndefinedConversionError using Omniauth in Gitlab 13.5.3 with Laravel Passport - macOS 上的本的主要内容,如果未能解决你的问题,请参考以下文章