python-o365 icon indicating copy to clipboard operation
python-o365 copied to clipboard

use : acquire_token_by_username_password

Open hitokiri opened this issue 3 years ago • 11 comments

Hello, for security reasons, I need to use the user and passsword to generate the token, I have done it with the MSAL library, but I wanted to know if there are plans to implement this in this library?

token = self.app.acquire_token_by_username_password(username=self.username, password=self.password, scopes=['.default'])

hitokiri avatar Jul 09 '22 02:07 hitokiri

We don't use MSAL although I'm very aware that we should use it, but I don't have the time to implement this.

We currently don't have any option to acquire the token by username and password.

alejcas avatar Jul 11 '22 09:07 alejcas

Hi @janscas , I know you don't have time, and I thank you for your work with this library, I just came up with that, I made a fix there by creating the token with the other library, and it worked perfectly, with yours, I had doubts if you were planning to aimplement that, that's why the question, but thanks again for your work.

hitokiri avatar Jul 12 '22 20:07 hitokiri

Sorry but I am a newcomer and I really get lost on how to access my account with this library. I have a personal email account at my university (which uses Office 365 services) and I just know my username and password. I would like to read all my emails using Python and regex-filter subjects to redirect some of them to a different account (gmail).

I looked into https://o365.github.io/python-o365/latest/usage/account.html#authenticating-your-account But I am so confused. I don't understand where do those 'my_client_id', 'my_client_secret' come from.

For what @janscas says I understand I cannot use this O365 library to access my emails from Python if I just know my username and password? But @hitokiri says I can't if I combine O365 with "the other library"?

Could any of you provide details about what that "other library" means, please? Perhaps msal-python? Or any explanation on how to get 'my_client_id', 'my_client_secret' starting from 'my_username', 'my_password' (in case that's possible at all).

Thanks a lot in advance @abubelinha

abubelinha avatar Nov 18 '22 18:11 abubelinha

Follow the readme it’s very well explained. The client secret and id comes from the app set up in azure portal. Check the readme and try

alejcas avatar Nov 18 '22 18:11 alejcas

Thanks again for your quick answer @janscas With "the app set up in azure portal" you mean these authentication steps?

To allow authentication you first need to register your application at Azure App Registrations.

Login at Azure Portal (App Registrations)

Create an app. Set a name.

So, in that "Azure login" is where I should use my university account username & address? I get this screen:

You do not have access

Your administrator has disabled the App registrations experience in the Azure portal. You can still register or manage applications using PowerShell or another client such as Visual Studio.

So, this means end of O365 story for me? :disappointed: What's that "PowerShell or Visual Studio" alternative proposed?

abubelinha avatar Nov 18 '22 18:11 abubelinha

Yep … ask the admin if they can provide access to set up an app or if they can set up one for you. That’s the only way

alejcas avatar Nov 18 '22 19:11 alejcas

Thanks, I just want to redirect messages to my Gmail, which suddenly stopped to grab them from other POP3 accounts (at least from outlook accounts). Do you know of any other Python libraries to just read an outlook.office365.com POP account?

abubelinha avatar Nov 18 '22 20:11 abubelinha

Not that I know…

alejcas avatar Nov 18 '22 20:11 alejcas

Thanks @jancas. I know this is not related to the original issue, but I'd have a more general question to understand how the authentication works.

Figure out what I am trying to do is a Python CLI application that anyone can use for reading his/her email (not just for me). I mean, something like Eudora or Mozilla Thunderbird desktop applications, that anybody can download, install, and configure pop/smtp servers plus his/her account username/password.

My university lets us use those applications. But in those cases, I think this step of "app set up in azure portal" is not necessary. I don't understand how it is possible for these apps to authenticate my user, but impossible for O365 Python apps.

Perhaps I can use a different Microsoft account to create the app (not my uni account), and then users authenticate in their own accounts through the app itself? (sorry I am talking about something I don't really understand how it works).

abubelinha avatar Nov 19 '22 09:11 abubelinha

The method used by this library is by setting that “app”. If there’s another way and what limitations may have I don’t know. I can’t tell right now other means of reading email, modifying excel, calendar stuff, one drive and etc.

anyway if you just need email maybe pop3 or others I don’t know about

alejcas avatar Nov 21 '22 20:11 alejcas

@hitokiri Please, would you be so kind to share the python code you employed to use O365 library by login with MSAL library and then sharing the token?

That would solve the issue for other people like me too.

Thanks a lot in advance!

abubelinha avatar Feb 24 '23 12:02 abubelinha