ruby 我不知道为什么解码完整性标记时出现400错误

vsnjm48y  于 2022-11-04  发布在  Ruby
关注(0)|答案(1)|浏览(173)

我正在使用ruby的库google-api-ruby-client的播放完整性,它为Android解密和google-apis-playintegrity_v1结果,但它返回了一个400错误。
我试图通过参考this article和其他来找到问题的原因,我想得到你的建议。
实现的源代码如下


# Gemfile

gem "google-apis-playintegrity_v1"
...

# API executable file

require 'google/apis/playintegrity_v1'

class AndroidRightfulnessCheck
  class << self
    def device_rightfulness_check( integrity_token: token)
      play_integrity = Google::Apis::PlayintegrityV1
      decode_integrity_token_request = play_integrity::DecodeIntegrityTokenRequest.new
      play_integrity_service = play_integrity::PlayIntegrityService.new
      cred = Google::Auth::DefaultCredentials.make_creds(json_key_io: StringIO.new(ENV["PRIVATE_KEY"]), scope: "https://www.googleapis.com/auth/playintegrity")
      play_integrity_service.authorization = cred

      integrity_token = decode_integrity_token_request.update!(integrity_token: integrity_token)
      payload = play_integrity_service.decode_integrity_token(package_name, integrity_token)
    end
  end
end

结果

Error - #<Google::Apis::ClientError: Invalid request status_code: 400 header: #<HTTP::Message::Headers:0x000055d11d04b098 @http_version="1.1"
, @body_size=0
, @chunked=false
, @request_method="POST"
, @request_uri=#<Addressable::URI:0x2ae88e7fa714 URI:https://playintegrity.googleapis.com/v1/package_name:decodeIntegrityToken?>
, @request_query=nil
, @request_absolute_uri=nil
, @status_code=400
, @reason_phrase="Bad Request"
, @body_type=nil
, @body_charset=nil
, @body_date=nil
, @body_encoding=#<Encoding:UTF-8>
, @is_request=false
...
body: "{\n  \"error\": {\n    \"code\": 400
,\n    \"message\": \"Integrity token cannot be decoded due to invalid arguments.\"
,\n    \"status\": \"INVALID_ARGUMENT\"\n  }\n}\n">

参考文件
https://www.rubydoc.info/gems/google-apis-playintegrity_v1/0.5.0/Google/Apis/PlayintegrityV1/PlayIntegrityServicehttps://www.rubydoc.info/gems/google-apis-playintegrity_v1/0.5.0/Google/Apis/PlayintegrityV1/DecodeIntegrityTokenRequest打印机

n53p2ov0

n53p2ov01#

已解决。
必须在更新后将decode_integrity_token_request指定为参数,而不是更新的令牌。
修改后


# Gemfile

gem "google-apis-playintegrity_v1"
...

# API executable file

require 'google/apis/playintegrity_v1'

class AndroidRightfulnessCheck
  class << self
    def device_rightfulness_check( integrity_token: token)
      play_integrity = Google::Apis::PlayintegrityV1
      decode_integrity_token_request = play_integrity::DecodeIntegrityTokenRequest.new
      play_integrity_service = play_integrity::PlayIntegrityService.new
      cred = Google::Auth::DefaultCredentials.make_creds(json_key_io: StringIO.new(ENV["PRIVATE_KEY"]), scope: "https://www.googleapis.com/auth/playintegrity")
      play_integrity_service.authorization = cred

      decode_integrity_token_request.update!(integrity_token: integrity_token) #changed
      payload = play_integrity_service.decode_integrity_token(package_name, decode_integrity_token_request) #changed
    end
  end
end

相关问题