python-o365
python-o365 copied to clipboard
Authentication interface solution
I am after some help if possible, please.
I am trying to get a solution for a web application to interact with Office 365, essentially the use case is the web application will need to send emails occasionally (invites, verification links and the like). I spent quite some time going through your documentation and tried the various authentication methods. I played around with the Web auth interface, but this didn’t seem to fit my scenario as I don’t want to use O365 as an identity provider for users to login to the web application, but rather want to send emails to users via the application.
So, the console-based authentication is the solution I eventually went with due to lack of complexities and it seemed to work well once authentication was setup.
However, this is proving problematic due to the manual interaction with the console if the mail server needs to reauthenticate.
from O365 import Account
credentials = ('CLIENT-ID', 'CLIENT-SECRET')
account = Account(credentials)
if not account.is_authenticated:
account.authenticate(scopes=['basic', 'message_all'])
I have looked through your docs’ numerous times and can’t find a way to avoid the need for the console-based auth. In your other authentication interfaces section 3, you mention the use of connection.get_authorization_url
and connection.request_token
but I cant seem to find any examples on how to use these. I am clearly missing something here and was hoping someone could maybe point me in the right direction, or point me in the direction of an example of using option 3?
I have since worked out I can use the get_authorization_url
however is it possible to simply build a o365_token.txt
file as the console method does?
from O365 import Account
scopes = ['https://graph.microsoft.com/Mail.ReadWrite',
'https://graph.microsoft.com/Mail.Send',
'https://graph.microsoft.com/offline_access']
credentials = ('CLIENT-ID', 'CLIENT-SECRET')
account = Account(credentials)
if not account.is_authenticated:
data = account.con.get_authorization_url(requested_scopes=scopes, redirect_uri='')
Read the readme: https://github.com/O365/python-o365#different-authentication-interfaces
It's explained under Web app based authentication interface using auth flow type authorization.
I have read that and tried it out, that to me looks like auth flow to allow users to auth into the application (type of identity provider)
@darryllane did you found out the solution, I am currently having issues in using the web based authentication and having the same problem, if you have worked on it please provide some sample code of how to use web based authentication.