0

I am trying to create a new device with this resouce:

https://cloud.google.com/identity/docs/reference/rest/v1beta1/devices/create.

I have defined the scopes for the API like below.

    @Override
    protected List<String> getScopes() {
        return Collections.singletonList(
                "https://www.googleapis.com/auth/cloud-identity"
        );
    }

I am calling the API create method like this.

            val createDeviceRequest = new CreateDeviceRequest()
                    .setCustomer("customers/my_customer")
                    .setDevice(createDeviceModel.toGoogle());
            
            cloudIdentityClientFactory
                    .createFor(adminGoogleId)
                    .devices()
                    .create(createDeviceRequest)
                    .execute();

"createDeviceRequest" entity value is like this:

enter image description here

There is no error about creating the client because creating the client works fine and I am able to call the list endpoint and get success response with 3 devices in the response body. I understand that the scope works fine because I am only using the 1 scope defined above and I have access to the listing devices.

https://cloud.google.com/identity/docs/reference/rest/v1beta1/devices/list

An example for the listing devices which works fine:

            val x = cloudIdentityClientFactory
                    .createFor(adminGoogleId)
                    .devices()
                    .list()
                    .setCustomer("customers/my_customer")
                    .execute();

When I try to call the create endpoint I get a 403 Forbidden error. I want to know about what's the cause of this forbidden message and is there any way to fix it.

POST https://cloudidentity.googleapis.com/v1beta1/devices
{
  "code" : 403,
  "errors" : [ {
    "domain" : "global",
    "message" : "The caller does not have permission",
    "reason" : "forbidden"
  } ],
  "message" : "The caller does not have permission",
  "status" : "PERMISSION_DENIED"
}

Thanks.

Berk Öztürk
  • 227
  • 1
  • 4
  • Have you tried using this scope "https://www.googleapis.com/auth/cloud-platform" as defined in the [public article](https://developers.google.com/identity/protocols/oauth2/scopes#healthcare) – Carlos Aug 27 '20 at 16:48

2 Answers2

1

I would recommend you post your question on Github instead.

They will probably better equipped to answer your question related to Java and the GCP API.

Frederic G
  • 45
  • 2
0

To create a new device you must need Enterprise Standard, Enterprise Plus, Enterprise for Education, and Cloud Identity Premium licenses to create a device. Better buy those licenses and try again.