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

[Feature Request] Office 365 Support? #858

Open
ziptbm opened this issue Oct 12, 2023 · 38 comments
Open

[Feature Request] Office 365 Support? #858

ziptbm opened this issue Oct 12, 2023 · 38 comments
Labels
feature New feature or request help wanted Extra attention is needed work-in-progress

Comments

@ziptbm
Copy link

ziptbm commented Oct 12, 2023

Is your feature request related to a problem? Please describe.

Unable to authenticate into my Office 365 inbox via this integration, but it works with Outlook.com accounts. I see the steps for configuration and the indication that it's WIP, so I'm curious if this is possible. https://github.com/moralmunky/Home-Assistant-Mail-And-Packages/wiki/Configuration-and-Email-Settings#office-365-wip

Describe the solution you'd like
The ability to use an Office 365 inbox.

Describe alternatives you've considered
Forwarding messages to an Outlook.com inbox for this, but that just seems excessive and not foolproof for missing mails.

@firstof9
Copy link
Collaborator

Implementing OAuth has proven more difficult than anticipated.

@firstof9 firstof9 added feature New feature or request work-in-progress labels Oct 12, 2023
@firstof9 firstof9 added the help wanted Extra attention is needed label Dec 19, 2023
@ghxstxch
Copy link

ghxstxch commented Feb 13, 2024

I'm sorry I can't offer my own help, but have you reached out to the people of this project? Another integration that I use (this one) uses this project and it work very well. My apologies if you've already traversed this path.

@firstof9
Copy link
Collaborator

I'll take a look, thanks.

@firstof9
Copy link
Collaborator

It seems those packages don't quite enable what we'd need to get this to work, but I've attempted to add Office365 support on this branch, if you'd like to give it a try.

You'll need your tenant ID, a client ID, and a secret, you should be able to use the info from the wiki to generate/obtain this information.

@firstof9
Copy link
Collaborator

Actually, you may want to skip trying this branch just yet, I need to hammer on it a bit more.

@ghxstxch
Copy link

Sounds good, I'm more than happy to test and help out where I can :)

@firstof9
Copy link
Collaborator

Ok I did some further updates, it might work now oauth-test let me know how it works out for you.

@ghxstxch
Copy link

Doesn't seem to work for me unfortunately -

image

Don't seem to see anything in logs.

@firstof9
Copy link
Collaborator

Thanks I'll keep hammering at it.

@firstof9
Copy link
Collaborator

Ok looks like I cleared up those issues now, you'll need to repull the files.

Thanks again for testing.

@ghxstxch
Copy link

No worries, I'm seriously glad I can help in some way :)

I'm still running into issues, but it seems like at least I'm getting further along.
image

All of them are copied directly from Azure.

@firstof9
Copy link
Collaborator

There should be an error in your home-assistant.log regarding this with more info.

@ghxstxch
Copy link

There should be an error in your home-assistant.log regarding this with more info.

Sorry, I thought it didn't generate anything in logs but I was just looking too quickly, here's what my logs say

2024-02-16 12:30:02.556 ERROR (MainThread) [custom_components.mail_and_packages.oauth] An error occured: invalid_request

Description: AADSTS9002331: Application '8179c266-8258-48f6-808a-f5fad0a69d66'(Mail and deliveries ) is configured for use by Microsoft Account users only. Please use the /consumers endpoint to serve this request. Trace ID: 9179b478-b454-4af5-9939-123fa00a2000 Correlation ID: 6354093c-542b-43cd-9db4-9af9dc2ce814 Timestamp: 2024-02-16 18:30:02Z

ID: 6354093c-542b-43cd-9db4-9af9dc2ce814

2024-02-16 12:30:02.556 ERROR (MainThread) [custom_components.mail_and_packages.config_flow] Problems obtaining oAuth token.

2024-02-16 12:30:05.038 ERROR (MainThread) [custom_components.mail_and_packages.oauth] An error occured: invalid_request

Description: AADSTS9002331: Application '8179c266-8258-48f6-808a-f5fad0a69d66'(Mail and deliveries ) is configured for use by Microsoft Account users only. Please use the /consumers endpoint to serve this request. Trace ID: c49129f1-0943-40ed-86c9-7597cf102200 Correlation ID: fac697cb-5aa5-444e-8410-cab3de039867 Timestamp: 2024-02-16 18:30:04Z

ID: fac697cb-5aa5-444e-8410-cab3de039867

2024-02-16 12:30:05.038 ERROR (MainThread) [custom_components.mail_and_packages.config_flow] Problems obtaining oAuth token.


@firstof9
Copy link
Collaborator

I just pushed another fix, however, you have to register the app using the Accounts in any organizational directory (Any Microsoft Entra ID tenant - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox) option rather than the Personal Accounts Only option.

Once you do this you have to add the API Office 365 Exchange Online from the API permissions section and add the IMAP.AccessAsApp permisison.

Example:
image

@ghxstxch
Copy link

Did both of these, however, still running into [custom_components.mail_and_packages.helpers] Error logging into IMAP Server: AUTHENTICATE failed.

Very possible I don't have something set right, but not sure where to look

@firstof9
Copy link
Collaborator

Ya that's as far as I get as well. From what I found searching it's because I don't have the Office 365 Exchange API stuff.

@firstof9
Copy link
Collaborator

Seems I'll need to use another approach for this.

@BMWfan
Copy link

BMWfan commented Mar 5, 2024

@firstof9 if you need someone in addition to test, please let me know. I can also not wait to use that function 😉.

@firstof9
Copy link
Collaborator

firstof9 commented Mar 5, 2024

It's slow going, but I have a plan.

@ilar
Copy link

ilar commented Apr 1, 2024

Is there something I can help with here? I'm very familiar with the nuts and bolts of oauth authentication, and I would like oauth support on this project so I can use it against a gmail account without an app password.

@firstof9
Copy link
Collaborator

firstof9 commented Apr 1, 2024

I'm still working on it when I have time.

@firstof9
Copy link
Collaborator

firstof9 commented Apr 1, 2024

Is there something I can help with here?

Basically we have to setup a a webhook pointing to https://my.home-assistant.io/api/webhook/mail_and_packages which, once setup by the user, will provide the refresh token/access token we need to store so we can then use the access token to login to IMAP. I welcome any PRs to help with this.

@ilar
Copy link

ilar commented Apr 2, 2024

Can you not use homeassistant.helpers's config_entry_oauth2_flow? From what I can tell that handles web hooks, refresh tokens, etc for you.

(Unfortunately, you went straight for asking questions about homeassistant instead of Oauth lol. Oauth I'm familiar with... homeassistant I started using about roughly 2 days ago)

I'm primarily looking at the fitbit integration. Specifically,
https://github.com/home-assistant/core/blob/dev/homeassistant/components/fitbit/api.py
https://github.com/home-assistant/core/blob/dev/homeassistant/components/fitbit/application_credentials.py
https://github.com/home-assistant/core/blob/dev/homeassistant/components/fitbit/config_flow.py

@firstof9
Copy link
Collaborator

firstof9 commented Apr 2, 2024

Can you not use homeassistant.helpers's config_entry_oauth2_flow?

If I use this method, there would need to be multiple version of the integration, one for each oauth email service, this is not ideal.

@ilar
Copy link

ilar commented Apr 2, 2024

Can you not just register additional implementations using different DOMAINs for a single integration?
Perhaps mailpackages_gmail, mailpackages_o365, etc?

@firstof9
Copy link
Collaborator

firstof9 commented Apr 2, 2024

No they'd have to go in a directory structure with that domain name.

@ilar
Copy link

ilar commented Apr 12, 2024

Hmm. Is Mail and Packages really the only addon/integration that wants to connect to more than one Oauth provider? Is there any way to have e.g. an oauth provider per entity, or per device, or something?

That might be something that makes sense to request as a feature add in HA itself if it's not possible, instead of re-implementing the wheel.

@firstof9
Copy link
Collaborator

As far as I am aware, yes the only integration looking to oauth multiple providers.

@ilar
Copy link

ilar commented Apr 21, 2024

just to check, does mail and packages need to connect to multiple oauth providers at the same time, or just have the capability to connect to multiple different providers?

@firstof9
Copy link
Collaborator

Just have the capability to connect to multiple different providers..

@ilar
Copy link

ilar commented Apr 23, 2024

Hm. Can you not use config_entry_oauth2_flow with a generic 'mail_and_packages' domain but not actually register the provider until the user has picked one? and just de-register/re-register it if they change their mind later? Because really, the only thing that changes is what URLs everything is pointed to and the JWKS, and those can be decided as needed, since it only needs to connect to a single one.

@firstof9
Copy link
Collaborator

Sadly the Home Assistant architecture doesn't work that way.

@ilar
Copy link

ilar commented Apr 24, 2024

Does it have to be set at server startup or app load or something? Sorry, I'm again unfamiliar with HA itself, and I'm not seeing any of that in the config flow code itself.

Reimplementing oauth is something we could totally do, but trust me, you want to exhaust all avenues before you pick up that maintenance burden lol

@firstof9
Copy link
Collaborator

I've exhausted all the standard HA ways to implement this.

@doug006
Copy link

doug006 commented Sep 21, 2024

@firstof9 Just came across this looking to use this with M365.

I noticed that the 0365-Home Assistant integration was already mentioned above. However, it seems the developer is starting to split them up into smaller more manageable pieces such as MS365-Mail.

Wanted to mention in case it would be helpful.

@firstof9
Copy link
Collaborator

I'll take a look, thanks.

@BMWfan
Copy link

BMWfan commented Nov 25, 2024

@firstof9 Do you have an update for us? Thanks in advance for your time and investigation.

@firstof9
Copy link
Collaborator

I have not updates on this at this time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request help wanted Extra attention is needed work-in-progress
Projects
None yet
Development

No branches or pull requests

6 participants