代码之家  ›  专栏  ›  技术社区  ›  Out of Control

编码::UnfinedConversion在Gitlab 13.5.3中使用Omniauth和Laravel Passport时出错-在macOS上使用Docker进行本地开发

  •  0
  • Out of Control  · 技术社区  · 3 年前

    现在有点不知所措,接下来该去哪里解决这个问题。有人能给我一个建议,让我看看或尝试让这个工作吗?如有需要,我们很乐意提供更多信息。

    概述:

    • macOS Catalina上的本地设置
    • oauth(客户端)GitLab 13.6.2在Docker的10080端口上运行
    • GitLab正在使用omniauth 1.8
    • oauth(服务器)使用Laravel Valet和Nginx在macOS上运行Laravel 8 Passport
    • Passport在本地Laravel网站上进行了测试,oauth流运行良好
    • 在Gitlab中,使用基于omniauth Gitlab 1.0.2的自定义omniauth gem( https://github.com/linchus/omniauth-gitlab )用于单点登录
    • /omniauth-site/lib/oniauth/strates/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上,点击“签名”按钮
    • 授权或取消按钮,单击授权
    • 使用以下URL返回GitLab:http://localhost:10080/users/auth/site/callback?code=def502005f52682329fdfb5e3554b245f48743a8494a4f37e55258e999961fc3db07815df6922142837de6036e810b4303c22cc3c147dc5307581ffebd65d0df5cc7968896b1b0d184f4db3dbbdfa20375f66b35a6c30b95f842685cce15b56dba795db29011f54b00396f395bb6f51ced3630a82ba18ec8ebf0760d9cb8b75088b6d3f41d39a1343a17c6ab81ecfac99819dde1c107a0c73c994770d4266819f3cadc47d12902121739d108a348cba521f0824f33ce066adf88c777f9049313b4ea1a720759f1fd447c4c66c9b6fd8c03242b56efa1c6ddc1ff33ea65f77aefa8f3f311fc7b7690a03da3c7de196f076373684f3f54b57ab004d2eb947a5e101421fb7de7fa1b224b1cff63147c7fb15717dd18c30deb448d8e07486d3582d7842104d57a6c9d3a5986760779ebe75bef9e9df9e10792ff7546828a1cf8a29b126ffe3dca181931cfab85cfe2d65df3efa8458ca763785532b99b41614f5490a2ceb7dab46dad02f2027be9ab75092b52c0710520ec74f22cdacf923a163a16fd62d13d8442d5b97cb6566832a4e8908112aaf905c4&状态=1f35df7bd654ca9c7786f83c7d4ace797ba9871746f8d3bc
    • 佩奇说:“哇,我们这边出了点问题。”
    • 在GitLab中,GitLab主力日志显示:
    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'
    
    0 回复  |  直到 3 年前
        1
  •  1
  •   Out of Control    3 年前

    这是一个狡猾的oauth2小错误,与回调没有直接关系。客户端在成功授权后已在尝试获取用户数据。/api/user路由中有一个错误,修复后解决了上述问题。

    根据我昨晚读到的内容,错误似乎是由于提供了一个HTML页面,而不是客户端在点击/api/user时期望看到的JSON数据。