Firebase REST Auth on Android returns 500 - firebase

Up until last week, the only resonable path available (for a lot of reasons) to use Firebase in a Xamarin.Android app required using Firebase.Xamarin. However, this appears to have stopped working as well.
Specifically, I had been able to successfully make the following call in my Android and iOS apps and get successful responses:
var contentString = $"grant_type=refresh_token&code=string&refresh_token={auth.RefreshToken}";
var requestContent = new StringContent(contentString, Encoding.UTF8, "application/x-www-form-urlencoded");
var uri = new Uri(string.Format("https://securetoken.googleapis.com/v1/token?key={0}", this.authConfig.ApiKey));
var response = await client.PostAsync(uri, requestContent).ConfigureAwait(false);
var responseData = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
As of yesterday, I started getting the following responseData from the above code:
iOS:
{
"error": {
"code": 403,
"message": "Requests from this ios client application \u003cempty\u003e are blocked.",
"status": "PERMISSION_DENIED",
"details": [
{
"#type": "type.googleapis.com/google.rpc.Help",
"links": [
{
"description": "Google developer console API key",
"url": "https://console.developers.google.com/project/<my_apps_project_id>/apiui/credential"
}
]
}
]
}
}
Android:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "ipRefererBlocked",
"message": "The request did not specify any Android package name or signing-certificate fingerprint. Please ensure that the client is sending them or use the API Console to update your key restrictions.",
"extendedHelp": "https://console.developers.google.com/apis/credentials?project=<my_apps_project_id>"
}
],
"code": 403,
"message": "The request did not specify any Android package name or signing- certificate fingerprint. Please ensure that the client is sending them or use the API Console to update your key restrictions."
}
}
After some research, I found this Google Cloud Endpoints Google Groups thread that said to be sure the following are in the http request's headers:
Header x-android-package
Label servicecontrol.googleapis.com/android_cert_fingerprint
Header x-android-cert
Label servicecontrol.googleapis.com/android_package_name
Header x-ios-bundle-identifier
Label servicecontrol.googleapis.com/ios_bundle_id
I added client.DefaultRequestHeaders.Add("X-Ios-Bundle-Identifier", <my_apps_bundle_id>); to my code before the client.PostAsync and it works like a charm.
Moving on to Android, I added "x-android-cert" and x-android-package to the request headers:
client.DefaultRequestHeaders.Add("x-android-cert", <my_apps_SHA1>);
client.DefaultRequestHeaders.Add("x-android-package", <my_apps_package_id>);
prior to my client.PostAsync call. However, now I get the following responseData:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "internalError",
"message": "Internal Error"
}
],
"code": 500,
"message": "Internal Error"
}
}
A moment of venting: For me, this is almost the last straw when it comes to Firebase. It has been over a month of overcoming one undocumented and half-baked API/SDK after another. It seems as if NOTHING works as advertised (including - off topic - getting Firebase working with an Angular4 project). Thank you for letting me share my frustration. Had I known how painful this was going to be, I would have setup my own MBaaS.
Before I give up on Firebase, I wanted to ask for help with this issue. Any insights and assistance would be greatly appreciated.
EDIT 1:*
I get similar results with the following changes:
var requestContent = new StringContent(postContent, Encoding.UTF8, "application/json");
var uri = new Uri(string.Format("https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyAssertion?key={0}", this.authConfig.ApiKey));

Related

Graph API Create new Group and Team - 'Invalid bind property name members in request' issue in Graph Explorer

I am trying to create a new group and team via the Graph API. I am trying to run the POST a request in Graph Explorer (https://developer.microsoft.com/en-us/graph/graph-explorer) as below but get a bad request.
Request: POST
Version: v1.0
URL: https://graph.microsoft.com/v1.0/teams/groups
Request Body:
{
"displayName":"Flight 157",
"mailNickname":"flight157",
"description":"Everything about flight 157",
"visibility":"Private",
"groupTypes":["Unified"],
"mailEnabled":true,
"securityEnabled":false,
"members#odata.bind":[
"https://graph.microsoft.com/v1.0/users/957c07af-dcad-4b72-9306-1c4ee7d04e1f"
],
"owners#odata.bind":[
"https://graph.microsoft.com/v1.0/users/957c07af-dcad-4b72-9306-1c4ee7d04e1f"
]
}
I get the below response error:
{
"error": {
"code": "BadRequest",
"message": "Invalid bind property name members in request.",
"innerError": {
"request-id": "fee10382-5112-44f8-a8c9-683453bdf050",
"date": "2020-03-05T01:08:19"
}
}
}
I am not quite sure what I am doing wrong. Can anyone please help me with this?

How to get permissions / scope for Google Apps Script to Firebase Cloud Messaging HTTP v1 API?

I am trying to send a Firebase Cloud Message from Google Apps Script. I have followed the following questions & links & assembled the following code:
Get 403 response with the "new" Firebase Cloud Messaging API
The res|error I am receiving is:
{
"error": {
"code": 403,
"message": "Request had insufficient authentication scopes.",
"status": "PERMISSION_DENIED"
}
}
My Code in Google Apps Script is:
function sendFCM(text){
text = {
"message": {
"topic": "news",
"notification": {
"title": "Breaking News",
"body": "New news story available."
},
"data": {
"story_id": "story_12345"
}
}
}
var projectId = "xxxxxxx";
var apiUrl = "https://fcm.googleapis.com/v1/projects/"+projectId+"/messages:send";
var authKey = "AAAU.......Cs";
var token = ScriptApp.getOAuthToken();
var options = {
'method' : 'post',
'contentType': 'application/json',
'muteHttpExceptions' : true,
'payload' : JSON.stringify(text),
headers:{Authorization: "Bearer "+ token},
};
var res = UrlFetchApp.fetch(apiUrl, options);
Logger.log(res);
}
Script's properties > User Scopes list follwoing:
https://www.googleapis.com/auth/firebase.database
https://www.googleapis.com/auth/script.external_request
https://www.googleapis.com/auth/spreadsheets
https://www.googleapis.com/auth/userinfo.email
FCM & GCM Api is enabled in project's developer console.
Edit:
From Ref's comment, I added the following scope to app manifest:
https://www.googleapis.com/auth/firebase.messaging
Upon Run, it asked me to authorize & now the response is an instance of a Message. But still I do not know how to define a to device i.e. to which device the message should go.
{
"name": "projects/send-xxxx3/messages/866xxxxx92"
}

Linkedin share on company page API is not working at all.

I am using Linking JS SDK and following below example for sharing a post on my company page:
https://developer.linkedin.com/docs/company-pages
I used blow code to share post:
// Build the JSON payload containing the content to be shared
function onSuccess(response){
console.log(response);
}
function onError(){
console.log(response);
}
var payload = {
"comment": "Check out developer.linkedin.com! http://linkd.in/1FC2PyG",
"visibility": {
"code": "anyone"
}
};
var cpnyID = 2414183;
IN.API.Raw("/companies/" + cpnyID + "/shares?format=json")
.method("POST")
.body(JSON.stringify(payload))
.result(onSuccess)
.error(onError);
in response i am getting:
{
"errorCode": 0,
"message": "Internal service error",
"requestId": "TZ1QE0M3VP",
"status": 500,
"timestamp": 1526892099561
}
i have tried with different user and many different company ids, i also tried with fresh user and fresh company pages, but every time "Internal Service Error" is returned from service.
Please Help.

How to make an API call to Youtube using meteor

I am trying to make an API call to
https://www.googleapis.com/youtube/v3/subscriptions
I'm trying to make it so when a user logs in using google-accounts they will be able to see their YouTube subscription list. It is currently not working at I am not sure why.
Im getting two errors in the console:
1.
www.googleapis.com/youtube/v3/subscriptions?part=subscriberSnippet&mine=true&key=MYKEY&part=snippet&mine=true:1
GET https://www.googleapis.com/youtube/v3/subscriptions?part=subscriberSnippet&…ne=true&key=MYKEY&part=snippet&mine=true 401 (OK)
2.
Object {statusCode: 401, content: "{↵ "error": {↵ "errors": [↵ {↵ "domain": "gl…e": 401,↵ "message": "Invalid Credentials"↵ }↵}↵", headers: Object, data: Object}content: "{↵ "error": {↵ "errors": [↵ {↵ "domain": "global",↵ "reason": "authError",↵ "message": "Invalid Credentials",↵ "locationType": "header",↵ "location": "Authorization"↵ }↵ ],↵ "code": 401,↵ "message": "Invalid Credentials"↵ }↵}↵"data: Objectheaders: ObjectstatusCode: 401__proto__: Object
My code looks as followed:
//client side
Meteor.autosubscribe(function(){
var newUser = Meteor.user();
Meteor.subscribe('currentAccessToken');
});
var url = "https://www.googleapis.com/youtube/v3/subscriptions?part=subscriberSnippet&mine=true&key=key";
var options = {
'headers' : {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + "currentAccessToken",
'X-JavaScript-User-Agent': "Google APIs Explorer"
},
'params' : {
part : 'snippet',
mine : 'true',
}
};
var searchResult = HTTP.call("get", url,options,
function (error, result) {
if (!error) {
Session.set("twizzled", true);
}
console.log(result);
});
On the server side I am publishing the access token so that it can be sent with the GET request
//Server Side
Meteor.publish("currentAccessToken", function(){
return Meteor.users.find(this.userId, {fields: {'services.google.accessToken': 1}});
});
I greatly appreciate any help or documentation.
The first thing to check would be authorization scopes. You have to explicitly add YouTube scope (more than one, actually, each defining single action or a small bunch of actions). To do that, you can use Accounts global object. Just add this code anywhere on the client side (inside client folder):
Accounts.ui.config({
requestPermissions: {
google: [
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/youtube',
'https://www.googleapis.com/auth/youtube.upload'
]
},
requestOfflineToken: {
google: true
}
});
The next time you authorize with Google, you should see that the popup asks not only for basic information but for YouTube access. For more information about YouTube Google API scopes, see official docs.

Failed to fetch events (404) from Google+ Calendars after OAuth 2.0 for limited devices

I'm writing a watchapp for Pebble to show events from the Google calendars.
I'm using Auth 2.0 to authenticate the user as described in this document.
Then I retrieve events using this API v3 call, specifying my access_token in the authorization header.
For the calendars created and managed by the user everything works fine.
However if I try to get the events from the Google+ calendars, such as Birthdays (#contacts#group.v.calendar.google.com) or Holidays in Italy (en.italian#holiday#group.v.calendar.google.com), the answer is 404:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "notFound",
"message": "Not Found"
}
],
"code": 404,
"message": "Not Found"
}
}
What am I doing wrong? Or is it a bug of the Calendar API?
Thanks to luc, here's the answer!
I was calling the service this way:
var GET_EVENT_LIST = "https://www.googleapis.com/calendar/v3/calendars/%s/events";
var calendarId = "#contacts#group.v.calendar.google.com";
var token_type = "Bearer";
var access_token = "...";
var url = sprintf(GET_EVENT_LIST, calendarId);
var req = new XMLHttpRequest();
req.open("GET", url, true);
req.setRequestHeader("Authorization", token_type + " " + access_token);
req.send(null);
I solved changing the fifth line to:
var url = sprintf(GET_EVENT_LIST, encodeURIComponent(calendarId));

Resources