Gmail API Service Account Issue - google-api

I am trying to send email using gmail api service account from spring boot api.
GoogleCredentials credentials = ServiceAccountCredentials.fromStream(inputStream)
.createScoped(Collections.singletonList(StorageScopes.DEVSTORAGE_FULL_CONTROL));
credentials = credentials.createScoped(SCOPES);
credentials.refresh();
AccessToken refreshToken = credentials.refreshAccessToken();
OAuth2Credentials credentialsAccess = OAuth2Credentials.create(refreshToken);
LOGGER.info("refresh token {}", credentials.refreshAccessToken().getTokenValue());
LOGGER.info("refresh token {}", credentialsAccess.getAccessToken().getTokenValue());
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(credentials);
Gmail service = new Gmail.Builder(new NetHttpTransport(), JacksonFactory.getDefaultInstance(),
requestInitializer).setApplicationName(APPLICATION_NAME).build();
Users a = service.users();
sendMessage(service, "me", mimeMessage);
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Precondition check failed.",
"reason" : "failedPrecondition"
} ],
"message" : "Precondition check failed.",
"status" : "FAILED_PRECONDITION"
}

Related

Elasticsearch, which path for elasticsearch.keystore is used?

I'm trying to understand why I get 401.
Steps taken:
created a elasticsearch.keystore
add the bootstrap.password successfully, with cat ~/.elk.secret | /opt/elasticsearch/bin/elasticsearch-keystore add -x 'bootstrap.password'
Since I've multiple instances running, I move it in the new conf directory
but now I get 401:
curl -X GET 'https://elastic:myFancyPass#myServer:9200/_cluster/health?pretty' -k
{
"error" : {
"root_cause" : [
{
"type" : "security_exception",
"reason" : "unable to authenticate user [elastic] for REST request [/_cluster/health?pretty]",
"header" : {
"WWW-Authenticate" : [
"Bearer realm=\"security\"",
"ApiKey",
"Basic realm=\"security\" charset=\"UTF-8\""
]
}
}
],
"type" : "security_exception",
"reason" : "unable to authenticate user [elastic] for REST request [/_cluster/health?pretty]",
"header" : {
"WWW-Authenticate" : [
"Bearer realm=\"security\"",
"ApiKey",
"Basic realm=\"security\" charset=\"UTF-8\""
]
}
},
"status" : 401
}
My understanding is that this error can be caused by two things:
wrong password (which I doubt it's my case)
wrong elasticsearch.file
How do I find which elasticsearch.keystore it is loading?
Running rootLogger.level = debug didn't help. I feel it would be great getting a confirmation such as /opt/elasticsearch/instance2/conf/elasticsearch.keystore

YouTube V3 LiveBroadcasts: list issue with service account credentials

I was trying to make list api call to get the list of upcoming live streams. But when I was using service account credentials the API is always responding with below status.
{
"code" : 403,
"errors" : [ {
"domain" : "youtube.liveBroadcast",
"message" : "The user is not enabled for live streaming.",
"reason" : "liveStreamingNotEnabled",
"extendedHelp" : "https://www.youtube.com/features"
} ],
"message" : "The user is not enabled for live streaming."
}
Please let me know if I have to assign any specific role in IAM for this particular service account to allow this API to work.

Set Customize Response for Reactive Web Service using Spring Boot and MongoDB as backend

I am developing reactive-spring-boot web service and also using reactive-mongodb to store data. I want to return my customize response for API. example as below:
[
{
"result": [
{
"code": "",
"data": "",
"error": ""
}
]
}
Sample Method:
#PostMapping(value="/addEmployee")
public Mono<Response> addEmployeeDetails(Employee employee){
Response response = new Response();
if(employee.getEmpID() == null){
return response(getResponse());
}
Repository.save(employee);
return response(getResponse());
}
As you see in the code I have response() method which builds the required response.But it mono gives default response as below:
{
"timestamp": "2018-09-29T16:23:21.287+0000",
"status": 500,
"error": "Internal Server Error",
"message": "Internal Server Error",
"path": "/employee"
}
I am not able to set my own status code and error message.

Listing Team Drive Files: Error 403 insufficientPermissions

I'm trying to access the files of my Team Drive, but I got a 403 error, while I can access to my files of my normal Google Drive.
Is it necessary to add a specific permission on the OAuth key ?
final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
Drive service = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT))
.setApplicationName(APPLICATION_NAME)
.build();
String pageToken = null;
do {
TeamDriveList result = service.teamdrives().list()
.setFields("nextPageToken, files(id, name)")
.setUseDomainAdminAccess(true)
.setPageToken(pageToken)
.execute();
for (TeamDrive file : result.getTeamDrives()) {
System.out.printf("Found file: %s (%s)\n",
file.getName(), file.getId());
}
pageToken = result.getNextPageToken();
} while (pageToken != null);
And the response :
Exception in thread "main" com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"message" : "Insufficient Permission",
"reason" : "insufficientPermissions"
} ],
"message" : "Insufficient Permission"
}

Google calendar api 3 invalid credentials error

I'm trying to access calendar details but I seem to get a invalid credentials error.
I access the following url: "https://www.googleapis.com/calendar/v3/calendars/{google_id}/events"
like this :
DefaultHttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(url_);
get.addHeader("Authorization","OAuth" + auth_token);
try {
HttpResponse response = client.execute(get);
What extra headers should I put there? I'm accessing it from an android application. If it matters I got my auth_token by an activity started with AccountManager.newChooseAccountIntent().
I'm getting the following json:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
There should be a space between OAuth and the token in your header.

Resources