Google Play 完整性 API 范围

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

我需要使用 Google Play Integrity API

我正在尝试使用此处文档中提供的范围 - https://googleapis.dev/dotnet/Google.Apis.PlayIntegrity.v1/latest/api/Google.Apis.PlayIntegrity.v1.PlayIntegrityService.Scope.html

但我收到此错误 - 服务 playintegrity 引发了异常。 HttpStatusCode 被禁止。请求的身份验证范围不足。

当我尝试打开链接本身时,我收到以下消息: *您收到此错误的原因可能是您输入的 OAuth2 范围名称无效,或者它引用了此旧版 API 域之外的较新范围。

此 API 是在范围名称格式尚未标准化时构建的。现在情况已不再如此,所有有效的范围名称(新旧)都在 https://developers.google.com/identity/protocols/oauth2/scopes 进行编目。使用该网页(手动)查找与您尝试调用的 API 关联的范围名称,并使用它来制作您的 OAuth2 请求。*

当我尝试在 https://developers.google.com/identity/protocols/oauth2/scopes 中搜索它时。我找不到它,我认为它可能已经停产了,但根据 GitHub 的说法,这个 API 最近似乎有开发。 https://github.com/googleapis/google-api-dotnet-client

该 API 在项目的 google cloud 中启用。 我还尝试将其添加到 Google OAuth 屏幕范围,但它也没有显示为可能的选项。

尝试访问此API时使用的代码:

UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
            new ClientSecrets
            {
                ClientId = "x",
                ClientSecret = "y"
            },
            new [] { "https://www.googleapis.com/auth/playintegrity"},
            "user",
            CancellationToken.None
        );
         

        var service = new PlayIntegrityService(new BaseClientService.Initializer
        {
            ApplicationName = "Test",
            HttpClientInitializer = credential
        });

        // Create the DecodeIntegrityTokenRequest body with your nonce as the IntegrityToken.
        DecodeIntegrityTokenRequest requestBody = new DecodeIntegrityTokenRequest()
        {
            IntegrityToken = nonce.ToString()
        };

        // The package name of the app.
        string packageName = "Test";

        // Create the DecodeIntegrityTokenRequest.
        V1Resource.DecodeIntegrityTokenRequest request = new V1Resource.DecodeIntegrityTokenRequest(service, requestBody, packageName);

        // Execute the request and get the response.
        DecodeIntegrityTokenResponse response = await request.ExecuteAsync();

        // Now, response.TokenPayloadExternal contains the decoded integrity payload.
        TokenPayloadExternal payload = response.TokenPayloadExternal;
google-api-dotnet-client
1个回答
0
投票

我的代码可以运行(C#、NetFramework)和 Google Cloud

  1. “在链接到您的应用的 Google Cloud 项目中创建一个服务帐号。在此帐户创建过程中,您需要向您的服务帐号授予服务帐号用户和服务使用消费者的角色。”。只需创建一个角色并在 Google Cloud 中分配 2 个角色即可
  2. 在帐户中创建密钥(类型为 JSON)并下载 .json
  3. 转到您的项目,添加 Google.Apis.PlayIntegrity.v1
  4. 调用代码
public TokenPayloadExternal Decrypt()
{
    var theGoogleCredential = GoogleCredential.FromJson({ JsonCredentials});

    var theInitializer = new BaseClientService.Initializer()
    {
        HttpClientInitializer = theGoogleCredential,
        ApplicationName = { ApplicationName }
    };
    var theRequest = new DecodeIntegrityTokenRequest()
    {
        IntegrityToken = { Attestation }
    };
    var theService = new PlayIntegrityService(theInitializer);
    var theResult = theService.V1.DecodeIntegrityToken(theRequest, { ApkPackageName});

    return theResult.Execute().TokenPayloadExternal;
}

JsonCredentials 是 .json

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