firebase.getToken() not a valid token - firebase

The function that gives me the registration Token returns the following string
eyJhbGciOiJSUzI1NiIsImtpZCI6ImQyZjQ0ZGVmNmE5MDkyYzlhYmYwNzJiMzM3ZDQ3OTVkZTFmZmNjY2UifQ.eyJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5jb20vZGFyay1zdHJhdHVtLTE5NDAxOSIsImF1ZCI6ImRhcmstc3RyYXR1bS0xOTQwMTkiLCJhdXRoX3RpbWUiOjE1MTgxNzUzODcsInVzZXJfaWQiOiI1YTY5ZTM4NjEzZWJkYmU4MGQ0MzhiOTciLCJzdWIiOiI1YTY5ZTM4NjEzZWJkYmU4MGQ0MzhiOTciLCJpYXQiOjE1MTgxNzUzODgsImV4cCI6MTUxODE3ODk4OCwiZmlyZWJhc2UiOnsiaWRlbnRpdGllcyI6e30sInNpZ25faW5fcHJvdmlkZXIiOiJjdXN0b20ifX0.rN76re5hzXkf03MFezbE5fvqJQ0XR46HZNOm9vAlPYr5hdr5LxP7Abbu5QK733WXVtwENwcv86HH2Q_jfxMlAzKwQRlHcU9g7-2wS1Q-jPIDfmc9-DziR4IgtrmJ3wt3mKl-3yS60PJdNhXOsg0PEt70GoWwEsaIsti4MEw87c470z9M8YRtCS_Q7yeEBZCs0MOTUmvfiFLVkrboPEgOf9zv7GFfRAuF3Zt-qOx9I-4GdUksuA2_mFCXXUEZ_eHkEWEdNl_wCT1ggMy7VMlQgFmRl00FXEgGSUIBLghejGDuJFT08CVsh5oLrHp2pKNSIShRnmL9RLJgnXTEzUz39A
whene I use this string as a token to send message it gives me an error :
{
"results": [
{
"error": {
"code": "messaging/invalid-registration-token",
"message": "Invalid registration token provided. Make sure it matches the registration token the client app receives from registering with FCM."
}
}
],
"canonicalRegistrationTokenCount": 0,
"failureCount": 1,
"successCount": 0,
"multicastId": 5998201396286625000
}
I think the registration token should be in this format :
cbuJIjkg9zQ:APA91bHavuWCuRuWIBrDOoHUK-RsjU1yewigurrYzHe0cP‌​iTQINykKjrLf8E0qEwJj‌​3XmJ1IoTmn0r2EoLR_mA‌​HGOjlA61CnQ8aSn2WxWK‌​KByOwbsnqoVeaeWQIeGU‌​_yh4wnZ67soLtI

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

Firebase short dynamic link authentication

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"
}
}

Field Value validation failed in REQUEST_BODY: Data Processing Exception while processing fields [/author] on linkedin ugcPost

Getting Error: Field Value validation failed in REQUEST_BODY: Data Processing Exception while processing fields [/author]
I have the "w_organization_social" permission in my app. I'm successfully getting the access token.
Can anyone help me what's going wrong?
Url: https://api.linkedin.com/v2/ugcPosts
Body:
{
"author":"urn:li:person:<id>",
"lifecycleState":"PUBLISHED",
"specificContent": {
"com.linkedin.ugc.ShareContent": {
"shareCommentary": {
"text":"Hello world"
},
"shareMediaCategory": "VIDEO",
"media":[{
"status":"READY",
"description": {
"text":"hello world"
},
"media":"urn:li:digitalmediaAsset:<asset_id>",
"title":{
"text":"hello world"
}
}]
}
},
"visibility":{
"com.linkedin.ugc.MemberNetworkVisibility":"PUBLIC"
}
}
Response:
{
"serviceErrorCode" : 100,
"message" : "Field Value validation failed in REQUEST_BODY: Data Processing Exception while processing fields [/author]",
"status" : 403
}
While getting access token, make sure that you pass r_liteprofile and w_member_social permissions in scope.
Then you have to send a GET request to https://api.linkedin.com/v2/me, to get the Lite Profile and you will get the ID from the response.
Use the ID you got from Lite Profile to generate Person URN,
eg: "urn:li:person:<ID>"

Firebase.auth error with 400 bad request

I found a strange error while I developing system using Firebase with service url contains user data.
User data is below.
{
"uid": "kt9Hcp2FbYbBvvIeSHHa1RbvHcv2",
"displayName": "Anonymous 901",
"photoURL": null,
"email": null,
"emailVerified": false,
"identifierNumber": null,
"isAnonymous": true,
"providerData": [
],
"apiKey": "MyApiKeyString",
"appName": "MyAppName",
"authDomain": "my.auth.domain",
"stsTokenManager": {
"apiKey": "MyApiKeyString",
"refreshToken": "refreshTokenString",
"accessToken": "accessTokenString",
"expirationTime": 1532451863076
},
"redirectEventId": null
}
I encode the above anonymous user data and include it in the service url.
( http://myserviceurl?userdata=encodedUserData )
Inside the system receives that url, firebase creates a user object with that user data contained in the url.
The purpose of this url is to use specific user's information in any browser.
However, when I call that service url, sometimes system creates user object well, sometimes got error -
400 Bad request errors with
https://www.googleapis.com/identitytoolkit/v3/relyingparty/setAccountInfo?key=MyApiKeyString
And error data is below,
{
"error": {
"code": 400,
"message": "TOKEN_EXPIRED",
"errors": [
{
"message": "TOKEN_EXPIRED",
"domain": "global",
"reason": "invalid"
}
]
}
}
Few hours later it works well, I changed nothing though.
I could not find the exact error point, but I suspect error occurs while observing authentication state or before this step.
Here is code snipets
#bind
private makeUserLoadingPromise(): Promise<void> {
let unSubscribe: () => void;
return new Promise<void>((resolve, _reject) => {
const onInitialized = this.makeOnInitializedAuthStateChanged(resolve);
unSubscribe = this.auth.onAuthStateChanged(onInitialized);
}).then(() => {
unSubscribe();
this.auth.onAuthStateChanged(this.onAuthStateChanged);
});
}
#bind
private makeOnInitializedAuthStateChanged(resolve: () => void) {
return (user: firebase.User | null) => {
this.user = user;
resolve();
};
}
#bind
private onAuthStateChanged(user: firebase.User | null) {
this.user = user;
}
Or maybe it relates with expirationTime?
I couldn't find any hints about this situation.
Any advice would be appreciated.
It is not clear what you are doing, but it appears that you are using the API incorrectly and insecurely. The plain user object contains a refresh token that is indefinite. Passing it around via URL is a really bad idea.
First don't rely on internal implementations, it is subject to change.
To get the user's information on your backend, the right way to do it, is to get the user's ID token using officially supported API, eg user.getIdToken(), then pass it to your server.
On your server, you verify it via the Firebase Admin SDK: admin.auth().verifyIdToken(idToken). Then you know this is a real authenticated user. If you need the full user info, you can then look it up using the decoded user id in the token: admin.auth().getUser(decodedIdToken.sub).

Getting Request had invalid authentication credentials error FCM

Am trying to test my web push notification from postman
my app id is thepostman-2018 so I am sending post requests to the url
https://fcm.googleapis.com/v1/projects/thepostman-2018/messages:send
event though I have set Authentication header and passed my Server key
i am getting this response
{
"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"
}
}
FCM v1 requests do not use the API key from the Firebase console to authorize requests. Instead, they use credentials retrieved by authenticating using the Service Account Key downloaded from the Firebase console. For example, this is how you generate the token using Node.js:
function getAccessToken() {
return new Promise(function(resolve, reject) {
var key = require('./service-account.json');
var jwtClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
SCOPES,
null
);
jwtClient.authorize(function(err, tokens) {
if (err) {
reject(err);
return;
}
resolve(tokens.access_token);
});
});
}
See the guide for more details.

Resources