Apple SSO 回调返回 OAuth2::AccessToken.from_hash `hash` 包含多个“令牌”密钥

问题描述 投票:0回答:1

我正在尝试使用 Ruby on Rails 中的

omniauth_apple
gem 来实现 Apple SSO。

在我的devise.rb中,我有以下配置

config.omniauth :apple, Rails.application.credentials.dig(Rails.env.to_sym, :apple_sso, :client_id), '', {
    scope: 'email name',
    team_id: Rails.application.credentials.dig(Rails.env.to_sym, :apple_sso, :team_id),
    key_id: Rails.application.credentials.dig(Rails.env.to_sym, :apple_sso, :key_id),
    pem: Rails.application.credentials.dig(Rails.env.to_sym, :apple_sso, :pem),
    redirect_uri: Rails.application.credentials.dig(Rails.env.to_sym, :apple_sso, :redirect_uri),
    provider_ignores_state: true
  }

在我的omniauth_callbacks_controller.rb中,我有以下内容

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  skip_before_action :verify_authenticity_token, only: [:apple]
  protect_from_forgery prepend: true, only: :apple
  
  def apple
    puts "==== GOT INTO APPLE======="
    auth_hash = request.env['omniauth.auth']
  end
end

我的用户.rb

class User < ApplicationRecord
  acts_as_tenant(:tenant)

  devise :database_authenticatable, :registerable, :recoverable, :lockable,
    :timeoutable, :rememberable, :trackable, :confirmable, :zxcvbnable,
    :omniauthable, :jwt_authenticatable,
    jwt_revocation_strategy: JwtDenyList, omniauth_providers: [:google_oauth2, :facebook, :apple]
end

在我的路线中,我还有接收每个提供商的回调的规范

devise_for :users,
    only: :omniauth_callbacks,
    controllers: {omniauth_callbacks: "users/omniauth_callbacks"}

现在,当我单击“使用 Apple 登录”按钮时,它会重定向我从 Apple 登录我的用户名和密码,但当启动回调阶段时,它会返回错误并且不会重定向到控制器。我收到此错误,但老实说我不知道如何或从哪里开始解决它

OAuth2::AccessToken.from_hash: `hash` contained more than one 'token' key (["access_token", "id_token"]); using "access_token".
(apple) Authentication failure! invalid_credentials: OmniAuth::Strategies::OAuth2::CallbackError, id_token_claims_invalid | nonce invalid

是否有人有使用omniauth_apple gem 与 Devise 来设置和完全集成 Apple SSO on Rails 的经验?请帮忙

ruby-on-rails devise omniauth apple-id
1个回答
0
投票

如果您希望能够使用用户名/密码以及omniauth登录,您可以找到解决方案这里

© www.soinside.com 2019 - 2024. All rights reserved.