The new Admin SDK API does not support the deprecated ClientLogin. You need to use OAuth 2.0 authentication.
Google Admin SDK operations using Client Login failing with 403 code even with Auth Token
-
06-08-2022 - |
Pergunta
I have downloaded admin-cmd-line-sample for Java and its working fine with oAuth, I am able to create users and groups. I have Admin SDK enabled also API usage in Security settings.
But I have to use old ClientLogin mechanism to create users and groups.
When asking for Authorization Token, Client Login returns me a value, which I eventually set in http request header and call the remote service.
But I get
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "dailyLimitExceededUnreg",
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
"extendedHelp": "https://code.google.com/apis/console"
}
],
"code": 403,
"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
}
}
I am using Client Login as follows.
ClientLogin authenticator = new ClientLogin();
authenticator.authTokenType = "apps";
authenticator.username = "foo@foo.com";
authenticator.password = "bar123#";
authenticator.transport = GoogleNetHttpTransport.newTrustedTransport();
final Response response = authenticator.authenticate();
Directory client = new Directory.Builder(GoogleApacheHttpTransport.newTrustedTransport(), JSON_FACTORY, new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
httpRequest.getHeaders().setAuthorization(response.getAuthorizationHeaderValue());
}
}).setApplicationName(APPLICATION_NAME).build();
Above client instance than I am using to create a user or group.
Group group = new Group();
group.setEmail("foo@foo.com");
group.setName("bar group");
group.setDescription("bar group");
client.groups().insert(group).execute();
If I make response.getAuthorizationHeaderValue() print on console, I can see a long string value.
I am using version directory_v1-rev16-1.16.0-rc of google-api-services-admin
Would really appreciate if someone could point where I am going wrong.
Solução