Firebase short dynamic link authentication - firebase

I am trying to create short dynamic link using Firebase REST API but I am getting 401 error every time when I use API key from project settings site:
This is how my request body looks like:
{
"dynamicLinkInfo": {
"domainUriPrefix": "https://xxxx.page.link",
"link": "https://xxxx.page.link",
"androidInfo": {
"androidPackageName": "com.example.android"
},
"iosInfo": {
"iosBundleId": "com.example.ios"
}
}
}
https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=xxxxxx
What I'm doing wrong? I have Deeplink service enabled. I am out of ideas.
EDIT 1.
This is how response looks like:
{
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}
}

Related

Google Calendar API Freebusy query returns "notFound" error

I'm trying to learn how to use this query; I created an API key and used Postman to
Post https://www.googleapis.com/calendar/v3/freeBusy?key="THE_API_KEY"
with this request body:
{
"timeMin": "2022-11-16T00:00:31-00:00",
"timeMax": "2022-11-16T14:00:00-00:00",
"groupExpansionMax": 100,
"calendarExpansionMax": 50,
"items": [
{
"id": "MY_OWN_GMAIL_ADDRESS"
},
{
"id": "OTHER_GMAIL_ADDRESS"
}
]
}
and got this response:
{
"kind": "calendar#freeBusy",
"timeMin": "2022-11-16T00:00:31.000Z",
"timeMax": "2022-11-16T14:00:00.000Z",
"calendars": {
"MY_OWN_GMAIL_ADDRESS": {
"errors": [
{
"domain": "global",
"reason": "notFound"
}
],
"busy": []
},
"OTHER_GMAIL_ADDRESS": {
"errors": [
{
"domain": "global",
"reason": "notFound"
}
],
"busy": []
}
}
}
What am I missing?
The Freebusy: query returns information about weither or not there is an event at the time of the request.
This method does not require authorization when being used against a public google calendar. There are a number of such calendars the holiday calendars are all public. You could also set your own calendar to public if you wish and then you would be able to use use an api key to access it.
API keys give you access to public methods only.
In order to access private user data. You need to be authorized using oauth2 with one of the following scopes.
If you do not have access to a calendar then it will return not found as you cant see it so your not going to be able to find it.
The solution i your case to fix your issue would be to either set the calendar to public and continue to use the api key. You will only be able to preform read actions against the calendar.
Or to switch to using oauth2 and send an authorization header with a bearer token.
Your post didnt include the Authorization header. Did you include it in your Postman Request?
Your need to send your Access Token as a Bearer Token in the Authorization Header
You can see an example for a request here:
https://developers.google.com/calendar/api/v3/reference/freebusy/query?apix=true#try-it

The request was missing an Authentication Key with push notification in firebase

I'm trying to send a push notification via REST API Firebase by Postman for specific user I followed below request pattern:
POST request with below URL :
https://fcm.googleapis.com/fcm/send?key=**my Web API key**
and the Body is
{ "data":
{
"title": "Firebase notification",
"detail": "I am firebase notification. you can customise me. enjoy"
},
"to" : "USER UID"
}
but the problem is it returns The request was missing an Authentication Key.
Kindly follow the steps as per bellow :
API URL: https://fcm.googleapis.com/fcm/send/
Request Method Post
Add 2 Key-value pairs in Header section like this
Content-Type : application/json
Authorization: key=[Your server key] (Make sure that no space allowed)
For body choose raw data (JSON)
{ "data": { "title": "Firebase notification", "detail": "I am firebase notification. you can customise me. enjoy" }, "to" : "USER UID" }

Firebase REST API signInWithCustomToken and Apple SignIn Provider

Context
iOS app written in Swift for iOS 13.2 (does NOT use Firebase iOS SDK)
App uses Firebase Realtime Database via REST calls (so needs an ID token from
Firebase Authentication)
I am trying to switch my iOS App to using Apple's "Sign in with Apple" feature, to replace the simple username / password authentication through the Firebase Authentication's "Email/Password" Sign-in provider .
A successful "Apple sign-in" by the user will leave me with a JWT token (identity token) from Apple, such as this one (decoded & edited) :
HEADER
{
"kid": "ABCDPK1",
"alg": "RS256"
}
BODY
{
"iss": "https://appleid.apple.com",
"aud": "XYZ.App",
"exp": 1574131940,
"iat": 1574131340,
"sub": "01234.1234561ecd054cd285d65cc7af261958.0123",
"c_hash": "ABCDe-csTpNdUa0Eri5wFw",
"email": "user#privaterelay.appleid.com",
"email_verified": "true",
"is_private_email": "true",
"auth_time": 1574131340
}
Problem
When I make use of the Firebase Authentication REST API to try and exchange a custom token for an ID and refresh token I get the following message (and yes, I have made sure the token wasn't expired when I used it) :
{
"error": {
"code": 400,
"message": "INVALID_CUSTOM_TOKEN",
"errors": [
{
"message": "INVALID_CUSTOM_TOKEN",
"domain": "global",
"reason": "invalid"
}
]
}
}
I was hoping that the new "Apple" sign-in method in Firebase Authentication would take care of that, once configured, and I could just pass in the JWT token from Apple. Am I missing a step ?
Thanks !
Ok, I guess I found the answer to my own question shortly after posting this (of course...).
I was using the wrong API endpoint. Instead I needed to use the Sign-in with OAuth credentials endpoint :
https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp?key={{apiKey}}
to get back :
{
"federatedId": "apple.com/ABCDEF.ABCDEF261958.1234",
"providerId": "apple.com",
"email": "user#privaterelay.appleid.com",
"emailVerified": true,
"localId": "123456786RbgQgxhzfSpyIJGLPIw1",
"idToken": "eyJABCDEFG.ABCDEFG.ABCDEFGiFQ",
"refreshToken": "AEu4IL1CY_PGF...6pN0DuQ",
"expiresIn": "3600",
"oauthIdToken": "eyJraWQiO...CJHHrxeg",
"rawUserInfo": "[JWT token info]",
"isNewUser": true,
"kind": "identitytoolkit#VerifyAssertionResponse",
"pendingToken": "AMzJoSn...HkvLeaOmFjNlcw"
}
The provided POST body should look something like :
{
"postBody": "id_token=eyJraWQiOiJBSURPUABCDEFGHIJKLMNOP.eyABCDEFGHIJKLMNOP2.KW0JABCDEFGHIJKLMNOP&providerId=apple.com",
"requestUri": "https://gpsstreaming.firebaseapp.com/__/auth/handler",
"returnIdpCredential": true,
"returnSecureToken": true
}
Note that the id_token is the 3-dot-notation token (JWT token) provided by Apple's Sign In With Apple ASAuthorizationAppleIDCredential -- data obfuscated here for obvious reasons. For example if you use SwiftUI, you get that from the completionBlock of the SignInWithAppleButton.

Need help registering Google Cloud Function URL as verified domain to receive push notifications

Am trying to call google calendar's push notification apis. I have written a google cloud function which just returns a response containing request body and headers. I want to use this google cloud function url as the receiving url for the push notification. The google docs mention steps to verify and register the domains, as part of which it asks me to upload a binary. Not sure how do upload a binary against this cloud function domain. My domain looks like https://asia-northeast1-project-name.cloudfunctions.net
This was my request for registering push notification:
Request:
POST
https://www.googleapis.com/calendar/v3/calendars/primary/events/watch?key={YOUR_API_KEY}
{ "id": "404713b9-d880-437d-b890-83715f01af7c", "type": "web_hook",
"address":
"https://asia-northeast1-huddle-quick-solutions.cloudfunctions.net/suratCalendarNotifications" }
Response:
{ "error": { "errors": [ {
"domain": "global",
"reason": "push.webhookUrlUnauthorized",
"message": "Unauthorized WebHook callback channel: https://asia-northeast1-project-name.cloudfunctions.net/path" } ], "code": 401, "message": "Unauthorized WebHook callback
channel:
https://asia-northeast1-project-name.net/path"
} }

Firebase REST Auth on Android returns 500

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));

Resources