firebase.messaging.deleteToken() FAILED when deleting token - firebase

I am trying stop web browser from receiving notification for cases where user logs out/ when oauth refresh token timeout (forced logout).
But when calling method firebase.messaging.deleteToken() with a valid token passed in as parameter, I keep getting errors "A problem occurred while unsubscribing the user from FCM: Requested entity was not found. (messaging/token-unsubscribe-failed)".
My use case and issue is same as described here, except for the part that I am using firebase 7.24.0.
I can't downgrade to firebase version 7.6.1(it is mentioned as a solution in the above mentioned GitHub thread) because I am also using messaging.onBackgroundMessage() and it has been added recently.

Related

Getting different errors when try to run report for GA4 with regular account

I am trying to run a simple report on GA4 by using Google Analytics Data API Python client with a regular user credentials:
request = RunReportRequest(
property=f"properties/11111",
dimensions=[Dimension(name=f['name']) for f in report_definition['dimensions']],
metrics=[Metric(name=f['expression']) for f in report_definition['metrics']],
date_ranges=[DateRange(start_date=date, end_date=date)],
)
response = client.run_report(request)
And the client is BetaAnalyticsDataClient as also mentioned in the documentation:
credentials = Credentials(
token=None,
refresh_token=config['refresh_token'],
client_id=config['client_id'],
client_secret=config['client_secret'],
token_uri="https://accounts.google.com/o/oauth2/token",
scopes=["https://www.googleapis.com/auth/analytics.readonly"]
)
client = BetaAnalyticsDataClient(credentials=credentials)
It is not a Service Account so I am using google.oauth2.credentials.Credentials class as same in other Google APIs.
However, this operation is throwing an exception during the run_report function:
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "Getting metadata from plugin failed with error: ('invalid_grant: Bad Request', {'error': 'invalid_grant', 'error_description': 'Bad Request'})"
debug_error_string = "UNKNOWN:Error received from peer analyticsdata.googleapis.com:443 {created_time:"2023-01-14T14:12:10.907813+03:00", grpc_status:14, grpc_message:"Getting metadata from plugin failed with error: (\'invalid_grant: Bad Request\', {\'error\': \'invalid_grant\', \'error_description\': \'Bad Request\'})"}"
>
And when I try to use my access token in the credentials:
credentials = Credentials(
token=config["token"],
refresh_token=config['refresh_token'],
client_id=config['client_id'],
client_secret=config['client_secret'],
token_uri="https://accounts.google.com/o/oauth2/token",
scopes=["https://www.googleapis.com/auth/analytics.readonly"]
)
This time I am getting following error:
google.api_core.exceptions.Unauthenticated: 401 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.
I am sure that my credentials is correct since I am using same account in my other repos.
Also, note that, I tried same operation with a service account and it does not give any error. However, for this purpose, I need to use a regular developer account since the OAuth flow is on a frontend project.
What are the suggestions on that issue? Is it possible to use a developer account in here and if yes, how?
I was able to fix the issue. The app just needs a sign-out sign-in (or refreshing the access token).

XSRF token expired after website publish to IIS

I am using ASP.NET Boilerplate framework, I put the below code in everypage.
#inject IAbpAntiForgeryManager AbpAntiForgeryManager
#{
AbpAntiForgeryManager.SetCookie(Context);
}
I call the app service as below:
var xhr = abp.services.app.order.add(data);
xhr.done(function (data) {
alert(data);
});
Everything works fine when I run in localhost, XSRF token will not expired even if I rebuild the project. Every time when I click [Publish website to IIS], all the ajax request will return 400 Bad Request, I guess it is because the XSRF token has expired, everything back to normal after I click F5 in browser. It was so annoying for the user, any thing I can do to prevent this error? Or auto refresh token?
Thank you!
update
error message in LOG file:
ERROR 2019-02-12 13:40:09,773 [71 ] .Antiforgery.Internal.DefaultAntiforgery - An exception was thrown while deserializing the token.
Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException: The antiforgery token could not be decrypted. ---> System.Security.Cryptography.CryptographicException: The key {996d31d2-0fa3-4ffe-8e82-e155c1486d33} was not found in the key ring.
Based on the error it sounds like your Data Protection keys have rotated on publish.
Check out the docs on Data Protection here: https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/introduction?view=aspnetcore-2.2.
There's a bunch of options how to configure it, where to store keys etc.
You'll want to change how it is storing them.
More on configuring Data Protection: https://learn.microsoft.com/en-us/aspnet/core/security/data-protection/configuration/overview?view=aspnetcore-2.2.

Firebase messaging failing on flutter after some time

I'm having an issue with FCM on flutter. I have implemented messaging from my server so I'm storing my phone token for each user.
The thing is that when a user logs in for the very first time everything works properly, messages are being sent and user gets notified.
If I do not use the app during the weekend, on Monday I try to send a message by doing some actions on my app but messages are not being sent. I can see my token stored properly in my database.
I'm using firebase_messaging 2.1.0 for flutter.
This is how I get my token
_fireBaseMessaging.getToken().then((token){
_myPhoneToken = token;
});
1-I know token may change when:
App deletes Instance ID
App is restored on a new device
User uninstalls/reinstall the app
User clears app data
But none of this happens.
Any advice on how to handle this scenario? thanks in advance.
UPDATE
Provided you have setup the FCM sdk the right way (but you said that it works the fist time you install the app, so I guess so).
Provided that you are sure that the device_token you are using is the one of the device on which you are expecting to receive the notification (check if it's still the same), you should get on this device your notification quite soon if you use "priority" : "high".
{
"to" : "device_token",
"priority" : "high",
"notification" : {
"sound": "default",
"body" : "Test Notification body",
"title": "Test Notification title"
}
}
This method call
_firebaseMessaging.getToken().then((String token)
return always the new token even if it has been updated. So if you print this out on your device and you send a notification on this token without error, there's no reason why you should not get the token if the device has a valid internet connection active.
It's true that the device token can change during time. If you uninstall and reinstall the app, you can see the token will change and if you try to send a notification on the old one, you will get an error.
If instead the token will change during application lifetime, you can be notify on your server side by listening:
_firebaseMessaging.onTokenRefresh.listen((newToken) {
_fcm_token = newToken;
// send the new fcm to your server
});
So first of all I suggest you to be able to send a notification to a device with Postman. Check if the token you are using is still the one on the device. Then you can try to uninstall and reinstall the application and try to use the old token. You will get an error. Then try to send to the new one, and you should get your notification.
Then wait for some days and try again, check if the token has changed or not and if it's not changed you should be able to send the notification without problems with the same token.
Also be aware that data message on Android if the app is terminated are still not supported.
Some networks/router/mobile can cut the connection between firebase library and firebase server due to inactivity (5min without message). This cut may be detected by the library up to 30min (FCM heatbeat interval).
These are some links discussing this issue:
https://github.com/firebase/quickstart-android/issues/307
Android: Delay in Receiving message in FCM(onMessageReceived)
I contacted firebase support but they told that since the issue is caused by external part they cannot fix it (I suggest decreasing heartbeat interval ...)
I fixed it in android using an interval job which apply these instructions:
context.sendBroadcast(new Intent("com.google.android.intent.action.GTALK_HEARTBEAT"));
context.sendBroadcast(new Intent("com.google.android.intent.action.MCS_HEARTBEAT"));
You may write this specific code for Android side and should find something similar for ios side.

Maximo Anywhere online-offline login issue

I am using Maximo Anywhere 7.5.2.0 - Work Execution App
The issue is , the online - offline login sometime getting failed. The first time of app flashed in the Ipad, I can able to login in the app for the both mode online and offline. After some time I cannot able to login. I got the "The user name and password combination that you entered is not valid" error even it is correct credentials.
I have enclosed the logs here.
Object {errorMsg: "The user name and password combination that you entered is not valid."} "
----------------------------------------
rejected at Object.<anonymous> (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/js/platform/auth/UserAuthenticationManager.js:498:17)
at http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/dojo/dojo.js:2:285161
at _7c0 (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/dojo/dojo.js:2:273376)
at _7ba (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/dojo/dojo.js:2:273240)
at _7d8.reject (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/dojo/dojo.js:2:274951)
at _7c6 (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/dojo/dojo.js:2:274017)
at _7c0 (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/dojo/dojo.js:2:273657)
at _7ba (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/dojo/dojo.js:2:273240)
at _7d8.reject (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/dojo/dojo.js:2:274951)
at AbstractChallengeHandler.<anonymous> (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/js/platform/auth/CustomChallengeHandler.js:98:18)
----------------------------------------
Error
at Promise.then._7cd.then (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/dojo/dojo.js:2:275189)
at declare.loginClickHandler (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/js/platform/handlers/LoginHandler.js:78:4)
at null.<anonymous> (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/js/platform/ui/control/UserInterface.js:850:47)
at HTMLButtonElement.<anonymous> (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/dojo/dojo.js:2:285161)
at Function.on.emit (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/dojo/dojo.js:2:557950)
at null.<anonymous> (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/js/platform/ui/control/UserInterface.js:139:12)
at HTMLFormElement.<anonymous> (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/dojo/dojo.js:2:285161)"_1047 # dojo.js:2(anonymous function) # dojo.js:2_142.filter # dojo.js:2_1055 # dojo.js:2
dojo.js:2 Object {responseJSON: Object, status: 401} "
----------------------------------------
rejected at AbstractChallengeHandler.<anonymous> (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/js/platform/auth/CustomChallengeHandler.js:98:18)
at http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/dojo/dojo.js:2:285161
at onLoginFormResponse (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/worklight/worklight.js:9549:5)
at klass.window.WLJSX.Ajax.Request.WLJSX.Class.create.respondToReadyState (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/worklight/worklight.js:1184:28)
at klass.window.WLJSX.Ajax.Request.WLJSX.Class.create.onStateChange (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/worklight/worklight.js:1117:9)
at XMLHttpRequest.<anonymous> (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/worklight/worklight.js:958:20)
----------------------------------------
Error
at Promise.then._7cd.then (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/dojo/dojo.js:2:275189)
at Object.<anonymous> (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/js/platform/auth/UserAuthenticationManager.js:400:52)
at http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/dojo/dojo.js:2:285161
at _7c0 (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/dojo/dojo.js:2:273376)
at Promise.then._7cd.then (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/dojo/dojo.js:2:275270)
at Object.lang.mixin._realmAuthentication (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/js/platform/auth/UserAuthenticationManager.js:398:4)
at Object.<anonymous> (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/js/platform/auth/UserAuthenticationManager.js:343:10)
at http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/dojo/dojo.js:2:285161
at _7c0 (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/dojo/dojo.js:2:273376)
at Promise.then._7cd.then (http://11.11.11.11:0989/MaximoAnywhere/apps/services/preview/WorkExecution/common/0/default/dojo/dojo.js:2:275270)
Even the different user with correct credentials not able to login. It is start working only I restarted the server. I faced this issue very often. Kindly advice.
Any help would be appreciated.
Thanks in advance
Offline login requires that you have logged in previously as this user before. It stores this information in the localStorage of the application. If offline login seems to be breaking on iOS, this might be a known issue that we've found and fixed as an iFix.
The first time you login, you must have a server connection to download the data initially and validate your username/password.
Are you using an embedded worklight or standalone worklight server? You should check the server logs to see if the server is actually running while you're trying to login as the second user.
UPDATE:
The only thing I can think of here, is that your worklight server is failing to respond to the initial WL.Client.connect somehow. Either it's too slow, or maybe running out of heap space. So when it's time to actually try and WL.login with our challenge handler, that handshaking has failed..
Check the heapsize of your worklight server make sure it's large enough
Check the connect timeout in our Startup.js file being used with the WL.Client.connect method, and bump it way up to be larger and see if it fixes the problem.

Web Api 2 Self Host with identity individual account

I have been trying to create a web api 2 that is secure with individual account.
So I can easily create WebApi2 with individual account, see link below
http://www.asp.net/vnext/overview/authentication/individual-accounts-in-aspnet-web-api
And Self hosting is easy to do.
http://www.asp.net/web-api/overview/hosting-aspnet-web-api/use-owin-to-self-host-web-api
But I cannot figure out how to combine the solutions.
Far as I got was adding a console app to a webapi2. Which seems to run. But whenever I try and get the access token it returns
An unhandled exception of type 'System.Net.WebException' occurred in System.dll
Additional information: The remote server returned an error: (500) Internal Server Error.
If anyone knows of a solution that would be great. Thanks
This post is way old, but to anyone else who is having this issue and finds this question, I was able to get past the 500 Error by adding app.UseWebApi(config); after setting up config, as mentioned in this post:
http://odetocode.com/blogs/scott/archive/2013/07/24/self-hosting-webapi-with-katana.aspx
HOWEVER, I'm now getting a 401, unauthorized request for all of my requests, even though I have a valid token and I'm sending it the same way I did that worked in the non-self-hosted WebApi2 app. but I'm one step closer anyways.

Resources