Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client Error 404 - JWT #251

Open
snfx-johaver opened this issue Sep 27, 2024 · 19 comments
Open

Client Error 404 - JWT #251

snfx-johaver opened this issue Sep 27, 2024 · 19 comments

Comments

@snfx-johaver
Copy link

I am getting the following errors in my log. Assuming as it’s unauthorised it’s not a connectivity error. Any suggestions?

Logger: O365.connection
Source: /usr/local/lib/python3.12/site-packages/O365/connection.py:838
First occurred: 05:08:37 (2 occurrences)
Last logged: 06:08:35

Client Error: 401 Client Error: Unauthorized for url: https://graph.microsoft.com/v1.0/me/calendars/AQMkADAwATNiZmYAZC1hNWU0LTRkMjAtMDACLTAwCgBGAAAD4vU1kwUsckqNhwP1OklERAAHAAKZhY2qtl1PpHI4Sk1x59AAAAIBBgAAAAKZhY2qtl1PpHI4Sk1x59AAAAEB-c8AAAA=/calendarView?%24top=999&startDateTime=2024-09-26T22%3A00%3A00%2B00%3A00&endDateTime=2024-09-27T22%3A00%3A00%2B00%3A00&%24select=seriesMasterId%2CshowAs%2Cstart%2Cbody%2Csubject%2Ccategories%2Cend%2CisAllDay%2Clocation%2Cattendees%2Csensitivity | Error Message: IDX14100: JWT is not well formed, there are no dots (.). The token needs to be in JWS or JWE Compact Serialization Format. (JWS): 'EncodedHeader.EncodedPayload.EncodedSignature'. (JWE): 'EncodedProtectedHeader.EncodedEncryptedKey.EncodedInitializationVector.EncodedCiphertext.EncodedAuthenticationTag'. | Error Code:
Client Error: 401 Client Error: Unauthorized for url: https://graph.microsoft.com/v1.0/me/calendars/AQMkADAwATNiZmYAZC1hNWU0LTRkMjAtMDACLTAwCgBGAAAD4vU1kwUsckqNhwP1OklERAAHAAKZhY2qtl1PpHI4Sk1x59AAAAIBBgAAAAKZhY2qtl1PpHI4Sk1x59AAAAEB-dEAAAA=/calendarView?%24top=999&startDateTime=2024-09-26T22%3A00%3A00%2B00%3A00&endDateTime=2024-09-27T22%3A00%3A00%2B00%3A00&%24select=seriesMasterId%2CshowAs%2Cstart%2Cbody%2Csubject%2Ccategories%2Cend%2CisAllDay%2Clocation%2Cattendees%2Csensitivity | Error Message: IDX14100: JWT is not well formed, there are no dots (.). The token needs to be in JWS or JWE Compact Serialization Format. (JWS): 'EncodedHeader.EncodedPayload.EncodedSignature'. (JWE): 'EncodedProtectedHeader.EncodedEncryptedKey.EncodedInitializationVector.EncodedCiphertext.EncodedAuthenticationTag'. | Error Code:

@RogerSelwyn
Copy link
Owner

RogerSelwyn commented Sep 27, 2024

Can you check your token file to see if the tokens look corrupted. This is the second time I've seen this reported.

How often do you get this error and does it recover? If you roll back to a previous version, does the issue go away?

@RogerSelwyn
Copy link
Owner

Can you post the full error from your logs. Also assuming that are intermittent, can you let me know if there is any specific time period between occurrences. Thanks

@RogerSelwyn
Copy link
Owner

I have spent some time today to ensure all call to the O365 library are async, to try and make sure that no calls to write the token are sync and therefore may get corrupted. Easier said than done, which is why this is beta at this time. It may or may not fix the problem, which may be more to do with your system than the code. That said I'm investigating because this is the second time of reporting, but am conscious that there are at least 3500 other install out there.

Please try it and report back if you have any problems - https://github.com/RogerSelwyn/O365-HomeAssistant/releases/tag/v4.8.6b1

@RogerSelwyn
Copy link
Owner

Not feedback, so closing

@snfx-johaver
Copy link
Author

@RogerSelwyn apologies for the delay, I missed your response on this!!
I have the errors today again, and they show up quite frequently in the past week.

Logger: O365.connection
Source: /usr/local/lib/python3.12/site-packages/O365/connection.py:838
First occurred: 05:26:33 (5 occurrences)
Last logged: 14:16:43

Client Error: 401 Client Error: Unauthorized for url: https://graph.microsoft.com/v1.0/me/calendars/AQMkADAwATNiZmYAZC1hNWU0LTRkMjAtMDACLTAwCgBGAAAD4vU1kwUsckqNhwP1OklERAAHAAKZhY2qtl1PpHI4Sk1x59AAAAIBBgAAAAKZhY2qtl1PpHI4Sk1x59AAAAEB-c4AAAA=/calendarView?%24top=999&startDateTime=2024-10-08T22%3A00%3A00%2B00%3A00&endDateTime=2024-10-09T22%3A00%3A00%2B00%3A00&%24select=start%2Clocation%2Ccategories%2CshowAs%2Cbody%2CseriesMasterId%2Cend%2Csubject%2Csensitivity%2CisAllDay%2Cattendees | Error Message: IDX14100: JWT is not well formed, there are no dots (.). The token needs to be in JWS or JWE Compact Serialization Format. (JWS): 'EncodedHeader.EncodedPayload.EncodedSignature'. (JWE): 'EncodedProtectedHeader.EncodedEncryptedKey.EncodedInitializationVector.EncodedCiphertext.EncodedAuthenticationTag'. | Error Code:
Client Error: 401 Client Error: Unauthorized for url: https://graph.microsoft.com/v1.0/me/calendars/AQMkADAwATNiZmYAZC1hNWU0LTRkMjAtMDACLTAwCgBGAAAD4vU1kwUsckqNhwP1OklERAAHAAKZhY2qtl1PpHI4Sk1x59AAAAIBBgAAAAKZhY2qtl1PpHI4Sk1x59AABCtzz-oAAAA=/calendarView?%24top=999&startDateTime=2024-10-09T04%3A26%3A27.702329%2B00%3A00&endDateTime=2024-10-10T04%3A26%3A27.702339%2B00%3A00&%24select=start%2Clocation%2Ccategories%2CshowAs%2Cbody%2CseriesMasterId%2Cend%2Csubject%2Csensitivity%2CisAllDay%2Cattendees | Error Message: IDX14100: JWT is not well formed, there are no dots (.). The token needs to be in JWS or JWE Compact Serialization Format. (JWS): 'EncodedHeader.EncodedPayload.EncodedSignature'. (JWE): 'EncodedProtectedHeader.EncodedEncryptedKey.EncodedInitializationVector.EncodedCiphertext.EncodedAuthenticationTag'. | Error Code:
Client Error: 404 Client Error: Not Found for url: https://graph.microsoft.com/v1.0/me/todo/lists/AQMkADAwATNiZmYAZC1hNWU0LTRkMjAtMDACLTAwCgAuAAAD4vU1kwUsckqNhwP1OklERAABAAKZhY2qtl1PpHI4Sk1x59AAAw-IQLYAAAA=/tasks?%24top=100&%24filter=status+ne+%27completed%27 | Error Message: <TITLE>Not Found</TITLE>

Not Found


HTTP Error 404. The requested resource is not found.

| Error Code:

Logger: custom_components.o365.calendar
Source: custom_components/o365/calendar.py:655
integration: Office 365 (documentation, issues)
First occurred: 05:26:33 (4 occurrences)
Last logged: 09:26:38

Error getting calendar events - 401 Client Error: Unauthorized for url: https://graph.microsoft.com/v1.0/me/calendars/AQMkADAwATNiZmYAZC1hNWU0LTRkMjAtMDACLTAwCgBGAAAD4vU1kwUsckqNhwP1OklERAAHAAKZhY2qtl1PpHI4Sk1x59AAAAIBBgAAAAKZhY2qtl1PpHI4Sk1x59AAAAEB-c4AAAA=/calendarView?%24top=999&startDateTime=2024-10-08T22%3A00%3A00%2B00%3A00&endDateTime=2024-10-09T22%3A00%3A00%2B00%3A00&%24select=start%2Clocation%2Ccategories%2CshowAs%2Cbody%2CseriesMasterId%2Cend%2Csubject%2Csensitivity%2CisAllDay%2Cattendees | Error Message: IDX14100: JWT is not well formed, there are no dots (.). The token needs to be in JWS or JWE Compact Serialization Format. (JWS): 'EncodedHeader.EncodedPayload.EncodedSignature'. (JWE): 'EncodedProtectedHeader.EncodedEncryptedKey.EncodedInitializationVector.EncodedCiphertext.EncodedAuthenticationTag'.
Error getting calendar events - 401 Client Error: Unauthorized for url: https://graph.microsoft.com/v1.0/me/calendars/AQMkADAwATNiZmYAZC1hNWU0LTRkMjAtMDACLTAwCgBGAAAD4vU1kwUsckqNhwP1OklERAAHAAKZhY2qtl1PpHI4Sk1x59AAAAIBBgAAAAKZhY2qtl1PpHI4Sk1x59AABCtzz-oAAAA=/calendarView?%24top=999&startDateTime=2024-10-09T04%3A26%3A27.702329%2B00%3A00&endDateTime=2024-10-10T04%3A26%3A27.702339%2B00%3A00&%24select=start%2Clocation%2Ccategories%2CshowAs%2Cbody%2CseriesMasterId%2Cend%2Csubject%2Csensitivity%2CisAllDay%2Cattendees | Error Message: IDX14100: JWT is not well formed, there are no dots (.). The token needs to be in JWS or JWE Compact Serialization Format. (JWS): 'EncodedHeader.EncodedPayload.EncodedSignature'. (JWE): 'EncodedProtectedHeader.EncodedEncryptedKey.EncodedInitializationVector.EncodedCiphertext.EncodedAuthenticationTag'.

@snfx-johaver
Copy link
Author

Can you check your token file to see if the tokens look corrupted. This is the second time I've seen this reported.

How often do you get this error and does it recover? If you roll back to a previous version, does the issue go away?

the calendars still seem to load and items show up correctly. i've had this for a while (months) also in previous versions.
How do I check if the tokens are corrupted exactly?

@RogerSelwyn
Copy link
Owner

The token file should look something like the below, the danger is if it fixes itself you may not see it ever corrupted.

{
 "token_type": "Bearer",
 "scope": [
  "Calendars.Read",
  "Calendars.ReadWrite",
  "Mail.Read",
  "Mail.Send",
  "Tasks.Read",
  "Tasks.ReadWrite",
  "User.Read",
  "profile",
  "openid",
  "email"
 ],
 "expires_in": 4390,
 "ext_expires_in": 4390,
 "access_token": "redacted",
 "refresh_token": "redacted",
 "expires_at": 1728511155.7669458
}

If it has been going on for months, that possibly rules out an issue I was concerned about, in that a change I implemented in 4.8.5 was the issue. That said, I have made further similar changes in 4.8.6 beta 1 prompted by warnings from HA core.

@RogerSelwyn RogerSelwyn reopened this Oct 9, 2024
@snfx-johaver
Copy link
Author

{
"token_type": "Bearer",
"scope": [
"User.Read",
"Mail.Send",
"Calendars.ReadWrite",
"Mail.Read",
"Tasks.Read"
],
"expires_in": 3600,
"ext_expires_in": 3600,
"access_token": "xxxxxxxxxx",
"refresh_token": "xxxxxxxxxx",
"expires_at": 1728509251.475176
}

@snfx-johaver
Copy link
Author

this is the token file , seems to look ok

@RogerSelwyn
Copy link
Owner

The implication is that it is the token that is corrupt, the bit that you have x'd out. I think the access token. And the message implies it should have dots '.' in it (mine does). Not sure if the problem is in the file or with when it is sent to MS.

@snfx-johaver
Copy link
Author

would deleting the integration and reinstalling it potentially work?

@RogerSelwyn
Copy link
Owner

I very much doubt it

@snfx-johaver
Copy link
Author

any suggestions on next steps? or should I leave it. this goes abit above my level of troubleshooting I guess :D

@RogerSelwyn
Copy link
Owner

You can try my latest beta. Other than that I'm at a loss. I'll try to follow it up with the library owner that handles the actual access token ms 365, it isn't my code, but I'll see what he suggests. I maxed out at the moment, so it may take a while.

@snfx-johaver
Copy link
Author

no problem, let me try and use the beta and keep an eye on my logs. perhaps its been shorter than I think :) thanks already!

@fion-private
Copy link

Hello @RogerSelwyn, I've the same issue.

Logger: custom_components.o365.calendar
Quelle: custom_components/o365/calendar.py:655
Integration: Office 365 (Dokumentation, Probleme)
Erstmals aufgetreten: 08:48:54 (1 Vorkommnisse)
Zuletzt protokolliert: 08:48:54

Error getting calendar events - 401 Client Error: Unauthorized for url: https://graph.microsoft.com/v1.0/me/calendars/AQMkADAwATNiZmYAZC04M2ZhLTkwNDYtMDACLTAwCgBGAAADxUpIqt1PQ02qEe37a0cywQcAe9JyutQAp0a3sg19Hw9tFgAAAgEGAAAAe9JyutQAp0a3sg19Hw9tFgAF1RvVAwAAAA==/calendarView?%24top=999&startDateTime=2024-11-08T07%3A48%3A44.399251%2B00%3A00&endDateTime=2024-11-09T07%3A48%3A44.399274%2B00%3A00&%24select=sensitivity%2Cstart%2Ccategories%2Cbody%2CisAllDay%2Csubject%2Cend%2Clocation%2CseriesMasterId%2Cattendees%2CshowAs | Error Message: IDX14100: JWT is not well formed, there are no dots (.). The token needs to be in JWS or JWE Compact Serialization Format. (JWS): 'EncodedHeader.EncodedPayload.EncodedSignature'. (JWE): 'EncodedProtectedHeader.EncodedEncryptedKey.EncodedInitializationVector.EncodedCiphertext.EncodedAuthenticationTag'.

Logger: O365.connection
Quelle: /usr/local/lib/python3.12/site-packages/O365/connection.py:838
Erstmals aufgetreten: 08:48:54 (1 Vorkommnisse)
Zuletzt protokolliert: 08:48:54

Client Error: 401 Client Error: Unauthorized for url: https://graph.microsoft.com/v1.0/me/calendars/AQMkADAwATNiZmYAZC04M2ZhLTkwNDYtMDACLTAwCgBGAAADxUpIqt1PQ02qEe37a0cywQcAe9JyutQAp0a3sg19Hw9tFgAAAgEGAAAAe9JyutQAp0a3sg19Hw9tFgAF1RvVAwAAAA==/calendarView?%24top=999&startDateTime=2024-11-08T07%3A48%3A44.399251%2B00%3A00&endDateTime=2024-11-09T07%3A48%3A44.399274%2B00%3A00&%24select=sensitivity%2Cstart%2Ccategories%2Cbody%2CisAllDay%2Csubject%2Cend%2Clocation%2CseriesMasterId%2Cattendees%2CshowAs | Error Message: IDX14100: JWT is not well formed, there are no dots (.). The token needs to be in JWS or JWE Compact Serialization Format. (JWS): 'EncodedHeader.EncodedPayload.EncodedSignature'. (JWE): 'EncodedProtectedHeader.EncodedEncryptedKey.EncodedInitializationVector.EncodedCiphertext.EncodedAuthenticationTag'. | Error Code:

I've checked my access token. There are no dots inside. I've also checked it with jwt.io and get the following error:

Error: Looks like your JWT Header is not encoded correclty using base64url (https://tools.ietf.org/html/rfc4648#section-5). Note that padding ("=") must be omitted as per https://tools.ietf.org/html/rfc7515'section-2

The error does not occur permanently, but only occasionally. It then seems to heal itself, since the synchronization of tasks and calendar (I don't use anything else) generally works.

Do you have any suggestions to solve the problem?

@RogerSelwyn
Copy link
Owner

Unfortunately the management of the token is completely outside of my control (apart from me saying where it should be stored). All I can do is report it to the python-o365 library owner. I did see something on a similar issue where they believed it was due to the time changing unreliably on the server and the refresh token being used before the access token had expired. I’ll raise an issue on their GitHub and tag you when I get a chance. I have never seen the problem myself, so very difficult to try and diagnose.

@RogerSelwyn
Copy link
Owner

Reported here - O365/python-o365#1111

@velodromen
Copy link

I too have the same issue. Seeing the response I'm only reporting it in order to follow any updates.

@RogerSelwyn RogerSelwyn pinned this issue Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants