Determine if my application is installed in the Google user domain on the market

When a user logs in, I want to check if Marketplace is installed on your domain. This seems to be theoretically possible with the Marketplace License API Endpoints .

However, when I try to use the Try Now feature for a Client License, User License, or License Notification , I always get a 403 ban with the message “Not authorized to access the application identifier”.

For example, if I try to request a LicenseNotification endpoint , I do the following:

Click the Authorization switch and click "Authorize" to allow this area for my registered user (who is the Google Apps administrator account that owns the application, by the way).

In the applicationId I then enter the 12-digit "Application Identifier" field from the Google Apps Marketplace SDK settings on the old developer console (also known as the "Project Number" on the developer apps overview page).

When I click "Run", I get 403 "Unauthorized access to the application identifier". I also tried using the project ID (that is, "my-app" on the "Overview of the Developer Console" page) instead of the project ID / application ID and get the same answer.

Did I miss something?

Otherwise, if someone knows of a different way for the owner of the GAM application to request a list of domains that he has installed, this would be the ideal solution for me - I could not find anything like that.

+6
source share
2 answers

Ok, read more and make it up at last.

What I was missing was that to authenticate licensing endpoints, you need to use a service account , not a regular user account. What makes sense is why the Try Now feature on the documentation pages doesn’t work at all.

Unfortunately, we use PHP, and google-api-php-client do not yet have services for the licensing API. However, the client project shows an example of using a service account instead of the user's normal OAuth2 stream.

I used this example and stole the source code a bit from the Resource.php call method to call the Client License Endpoint to check if our application is installed in the domain or not:

 $privateKey = file_get_contents('path/to/private-key.p12'); $serviceAccountName = ' 12345-j@developer.gserviceaccount.com '; $cred = new \Google_Auth_AssertionCredentials( $serviceAccountName, array('https://www.googleapis.com/auth/appsmarketplace.license'), $privateKey ); $client = new \Google_Client(); $client->setApplicationName('Apps_Marketplace_Licensing_Check'); $client->setAssertionCredentials($cred); if ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion($cred); } $url = \Google_Http_REST::createRequestUri( 'appsmarket/v2/', 'customerLicense/{appId}/{customerId}', [ 'appId' => ['location' => 'path', 'type' => 'string', 'value' => $appId], 'customerId' => ['location' => 'path', 'type' => 'string', 'value' => $domain] ] ); $httpRequest = new \Google_Http_Request($url, 'GET'); $httpRequest->setBaseComponent($client->getBasePath()); $httpRequest = $client->getAuth()->sign($httpRequest); /* returns JSON array */ $result = $client->execute($httpRequest); $isDomainInstalled = ($result && isset($result['state']) && $result['state'] == 'ACTIVE'); 

We hope that the people in the google-api-php-client project will eventually add the true service for these endpoints, but so far this workaround is not too terribly painful.

+6
source

The licensing API can help you get the information you need https://developers.google.com/google-apps/marketplace/v2/developers_guide

0
source

Source: https://habr.com/ru/post/978875/


All Articles