Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在Ruby中获取NoMethodError未定义方法_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails 在Ruby中获取NoMethodError未定义方法

Ruby on rails 在Ruby中获取NoMethodError未定义方法,ruby-on-rails,ruby,Ruby On Rails,Ruby,在有效的\u限制下获取NoMethodError未定义的方法服务\u帐户\u id?方法。 有人能检查一下我为什么会出现这个错误吗 如果你有解决这个问题的链接,那也会很有帮助。谢谢 错误: 错误: 请显示完整的错误,而不仅仅是一个片段。这可能是nil,也可能是该对象上不存在您认为存在的方法。@tadman错误:如果该标记是字符串,那么您将无法对其调用任意方法,是吗?你确定那是正确的类型吗?也许你的“解码令牌”实际上没有被解码。@tadman解码的令牌基本上是一个GCP身份令牌(jwt有效负载)…

在有效的\u限制下获取
NoMethodError未定义的方法服务\u帐户\u id
?方法。 有人能检查一下我为什么会出现这个错误吗

如果你有解决这个问题的链接,那也会很有帮助。谢谢 错误: 错误:


请显示完整的错误,而不仅仅是一个片段。这可能是
nil
,也可能是该对象上不存在您认为存在的方法。@tadman错误:如果该标记是
字符串
,那么您将无法对其调用任意方法,是吗?你确定那是正确的类型吗?也许你的“解码令牌”实际上没有被解码。@tadman解码的令牌基本上是一个GCP身份令牌(jwt有效负载)…似乎不是这样。你确定你解码了吗?您确定在传递该变量之前已将解码结果赋给该变量吗?
module Authentication
  module AuthnGcp

    class DecodedToken

      PROJECT_ID_TOKEN_CLAIM_NAME = "google/compute_engine/project_id"
      INSTANCE_NAME_TOKEN_CLAIM_NAME = "google/compute_engine/instance_name"
      SUB_TOKEN_CLAIM_NAME = "sub"
      EMAIL_TOKEN_CLAIM_NAME = "email"
      AUDIENCE_TOKEN_CLAIM_NAME = "aud"

      attr_reader :project_id, :instance_name, :service_account_id, :service_account_email, :audience

      def initialize(decoded_token_hash:, logger:)
        @decoded_token_hash = decoded_token_hash
        @logger = logger

        initialize_required_claims
        initialize_optional_claims
      end

      private

      def initialize_required_claims
        @audience = required_token_claim_value(AUDIENCE_TOKEN_CLAIM_NAME)
        @service_account_id = required_token_claim_value(SUB_TOKEN_CLAIM_NAME)
      end

      def initialize_optional_claims
        @service_account_email = optional_token_claim_value(EMAIL_TOKEN_CLAIM_NAME)
        @project_id = optional_token_claim_value(PROJECT_ID_TOKEN_CLAIM_NAME)
        @instance_name = optional_token_claim_value(INSTANCE_NAME_TOKEN_CLAIM_NAME)
      end

      def required_token_claim_value(required_token_claim)
        required_token_claim_value = token_claim_value(required_token_claim)

        if required_token_claim_value.nil? || required_token_claim_value.empty?
          raise Errors::Authentication::Jwt::TokenClaimNotFoundOrEmpty, required_token_claim
        end

        log_claim_extracted_from_token(required_token_claim, required_token_claim_value)

        required_token_claim_value
      end

      def optional_token_claim_value(optional_token_claim)
        optional_token_claim_value = token_claim_value(optional_token_claim)

        if optional_token_claim_value.nil? || optional_token_claim_value.empty?
          optional_token_claim_value = nil
          @logger.debug(LogMessages::Authentication::Jwt::OptionalTokenClaimNotFoundOrEmpty.new(optional_token_claim))
        else
          log_claim_extracted_from_token(optional_token_claim, optional_token_claim_value)
        end

        optional_token_claim_value
      end

      def token_claim_value(token_claim)
        token_claim_path = token_claim.split('/')
        @decoded_token_hash.dig(*token_claim_path)
      end

      def log_claim_extracted_from_token(token_claim, token_claim_value)
        @logger.debug(
          LogMessages::Authentication::Jwt::ExtractedClaimFromToken.new(
            token_claim,
            token_claim_value
          )
        )
      end
    end
  end
end
module Authentication
  module AuthnGcp

    # This class is responsible for retrieving the correct value from the GCP token
    # of the requested attribute.
    class AuthenticationRequest
      def initialize(decoded_token:)
        @decoded_token = decoded_token
      end

      def valid_restriction?(restriction)
        token_value =
          case restriction.name
          when Restrictions::PROJECT_ID
            @decoded_token.project_id
          when Restrictions::INSTANCE_NAME
            @decoded_token.instance_name
          when Restrictions::SERVICE_ACCOUNT_ID
            @decoded_token.service_account_id
          when Restrictions::SERVICE_ACCOUNT_EMAIL
            @decoded_token.service_account_email
          end

        raise Errors::Authentication::AuthnGcp::JwtTokenClaimIsMissing, restriction.name if token_value.blank?

        token_value == restriction.value
      end
    end
  end
end