簡體   English   中英

omniauth_openid_connect gem - 身份驗證失敗:invalid_request: Rack::OAuth2::Client:,Error: invalid_request:: 客戶端憑據無效

[英]omniauth_openid_connect gem - Authentication failure! invalid_request: Rack::OAuth2::Client::Error, invalid_request :: Client credentials are invalid

我使用這個gem將 Omniauth OpenID 添加到提供程序中。

我在 Devise Initializer 中配置了 gem,一切似乎都是正確的:

config.omniauth :openid_connect,
  {
      name: :openid_connect,
      scope: %i[openid profile groups_rewardops scope_rewardops],
      issuer: ConfigSettings.desjardins.issuer_url,
      response_type: :code,
      uid_field: 'sub',
      response_mode: :query,
      discovery: true,
      send_scope_to_token_endpoint: false,
      client_options:
      {
        port: 443,
        scheme: "https",
        host: ConfigSettings.desjardins.host,
        authorization_endpoint: "/affwebservices/CASSO/oidc/rewardops/authorize",
        token_endpoint: "/affwebservices/CASSO/oidc/rewardops/token",
        userinfo_endpoint: "/affwebservices/CASSO/oidc/rewardops/userinfo",
        identifier: ConfigSettings.desjardins.client_id,
        secret: ConfigSettings.desjardins.client_secret,
        redirect_uri: "#{ConfigSettings.api.base_url}front_end/users/auth/openid_connect/callback",
      },
  }

我有 atm 的流程是用戶可以登錄並從提供程序授予訪問權限,然后提供程序向我的 devise 回調 url 發送請求,其中包含noncecodestate 此時一切似乎都是正確的,但是當嘗試生成access_token並出現以下錯誤時,該請求以failure

ERROR -- omniauth: (openid_connect) Authentication failure! invalid_request: Rack::OAuth2::Client::Error, invalid_request :: Client credentials are invalid.

我確定identifiersecret是正確的,不明白發生了什么。

由於我使用discovery模式,因此提供者的所有配置都在.well-known中,您可以在此處查看

我被阻止了,沒有關於如何調試錯誤的想法。 檢查Rack::OAuth2以查看錯誤來自哪里,我發現說:

 invalid_request: "The request is missing a required parameter, includes an unsupported parameter or parameter value, repeats the same parameter, uses more than one method for including an access token, or is otherwise malformed.",

似乎由於某種原因訪問令牌請求格式不正確,但不確定除了identifiersecret之外我還應該記住什么? 我已經看到了許多其他配置示例,我的似乎是正確的。

由於您確定您的憑據正確,我懷疑正在使用的身份驗證方法與提供者支持的方法不匹配。 檢查.well-known配置,我看到這個提供程序只支持client_secret_post 在您的omniauth 配置中,我看到沒有傳遞任何選項來指定身份驗證方法。 當我深入研究代碼時,我看到底層 oauth2 gem 默認使用basic身份驗證,它使用標識符和secret來構造Authentication indentifier 見: 源代碼在這里

client_auth_method = args.first || options.delete(:client_auth_method).try(:to_sym) || :basic

    case client_auth_method
    when :basic
      cred = Base64.strict_encode64 [
        Util.www_form_url_encode(identifier),
        Util.www_form_url_encode(secret)
      ].join(':')
      headers.merge!(
        'Authorization' => "Basic #{cred}"
      )

client_secret_post認證方法中,客戶端授權自己在 HTTP 請求正文中提供密鑰作為表單參數,而不是在 header 中提供客戶端密鑰。 因此,該提供商看不到您的憑據。 您可以通過查看令牌端點請求的日志來驗證這一點,該日志在瀏覽器中不可見,而是從您的 rails BE 到提供者的服務器。

嘗試在您的omniauth 配置中的client_options hash 中傳遞一個client_auth_method 如果您查看我上面鏈接到的代碼中的 case 語句,似乎沒有client_secret_post的命名選項,但它是默認情況。 client_auth_method的任何值看起來都可以,但我仍然會使用client_secret_post

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM