Тёмный

How to connect to Office 365 with IMAP, Oauth2 and Client Credential Grant Flow 

CodeWrecks
Подписаться 1,4 тыс.
Просмотров 75 тыс.
50% 1

You can find a blog post on my english blog at this address www.codewrecks... that has a recap.
I've published another video on this subject here • Office 365 - MailKit -...
Previous video on the subject • How to connect to offi...
Code use in the video is on my GitHub repository (github.com/alk...) that explain how to use OAUT2 to obtain a User Token that can be used to access Office 365 with IMAP protocol and OAuth2.
This is needed because Microsoft will deprecate and remove the basic authentication.
This is a practical implementation of official instructions docs.microsoft... with the complete code to perform OAuth2 Client login.

Опубликовано:

 

16 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 132   
@jasonlokismith
@jasonlokismith Год назад
Tonight i will be praying and saying thank you that you exist and created this video. i was struggling so much, this REALLY helped me a lot THANK YOU!
@codewrecks
@codewrecks Год назад
You are so welcome
@lakelse2
@lakelse2 2 года назад
I can't overstate how helpful this video was. Thank you!
@ABiggrBoat
@ABiggrBoat 2 года назад
Fantastic stuff here! Thanks so much for creating. This worked for me. I will add that I had to run: Install-Module -Name AzureADPreview -AllowClobber to install the preview version which I believe includes the New-ServicePrincipal cmdlet. I also had to add: Install-Module -Name PackageManagement -Repository PSGallery -Force Install-Module -Name PowerShellGet -Repository PSGallery -Force to enable the -prerelease switch to work. Crazy how laborious MS made it to read an email account!
@codewrecks
@codewrecks 2 года назад
New-ServicePrincipal was downloaded once you connected to your tenant, maybe MS changed this and included in the base module :), it was one of the most annoying thing for me, because I was trying using a tenant where I had insufficient permission and I got in return that New-ServicePrincipal was not recognized (a message like "you do not have enough privilege would have been welcomed") For the "how laborious MS", I can agree, but this is OAuth2 standard, it is really more work to do, but in the end it is more secure, and given that EMails are an important asset, I really appreciate that they took a bald move and made it a Must. A more comprehensive documenation and extensive examples would have been made the transition easier.
@livingdeathD
@livingdeathD 2 года назад
@@codewrecks thanks!!, I was stuck at this point and the problem was that my user did not have the necessary permissions in the tenant😘
@ciaocato
@ciaocato Год назад
​@@codewrecks Grazie mille per il video. Sono però bloccato con il comando "New-ServicePrincipal" che non riesce ad essere riconosciuto come cmdlet valido. Ho installato tutti i moduli powershell necessari; lato User l'ho abilitato ad ogni permesso e ruolo possibile sul Tenant, mi domando quindi se ci sono suggerimenti specifici per poter superare la problematica. Grazi mille
@GianMariaRicci
@GianMariaRicci Год назад
Nel mio caso erano permessi insufficienti (ma potrebbe anche essere forse essersi connessi ad un tenant sbagliato). Purtroppo se qualche cosa non va (usualmente permessi) l'errore è quello invece di cmdlet non presente, che è abbastanza fuorviante.
@ciaocato
@ciaocato Год назад
@@GianMariaRicci Sto effettivamente indagando sui permessi del tenant (è unico e ho già verificato tramite ID di collegarmi a quello ove è presente la mia app). A memoria, ricordi per caso quali fossero i permessi necessari? Io utilizzo un utente che oltre ad essere TenantAdminn è anche: Company Administrator, Exchange Administrator, Security Administrator, Privileged Role Administrator. Grazie mille
@philpretable
@philpretable Год назад
You were an absolute life saver. Thank you so much for making a really complex issue, thnx to MS, clear for mere mortals like me.
@rodrigodearcayne
@rodrigodearcayne Год назад
Really really helpful, thank you! By now you can skip the -PreRelease flag as those powershell modules are generally available. Also I found that you don't need the Graph API module at all.
@codewrecks
@codewrecks Год назад
Yes, some stuff changed since the video was recorded, thanks for the clarification.
@scottstemen5894
@scottstemen5894 Год назад
Thank you, This is a brilliant and clear explanation of how to get MS OAuth2 connected to Outlook Office 365. You may have just saved my job.
@babatundeafolabi5340
@babatundeafolabi5340 Год назад
I am not so familiar with Visual studio he used here and I am lost as to how he got to all these commands and which templates he used. I mean the visual studio part. Can you help with where all those commands come from, How I can replicate it on my Visual studio?
@20055416
@20055416 2 года назад
One of the best instructions I've seen so far. Thank you!
@davidpillot
@davidpillot 2 года назад
How are we supposed to understand how this Principal works only with Microsoft documentation ? I hope I will be able to use OAuth authentication in my application to connect to mailbox in imap, thanks to that video.
@AJZbrun-IOD
@AJZbrun-IOD 9 месяцев назад
I can't belive that Microsoft made this difficult for us to connect to azure and be able to read a mailbox. All those steps outside the project (powershell commands and so) with what purpose? Just to add difficult to the process. Thanks man! nice video.
@codewrecks
@codewrecks 9 месяцев назад
Actually the problem is that OIDC and OAUTH2 were standard from long time but very few developer study them to use in their application. Google and other big player are gradually enforcing OAUTH2 everywhere. The real problem is that we lacked an official C# library with really clear step by step instruction on how to put everything in place. Also some of the CMDLet for sharepoint were released late generating a lots of confusion :(
@themotivator9795
@themotivator9795 2 года назад
An excellent video turned out, everything is well thought out, a very clear instruction turned out)))
@bluehippotech
@bluehippotech 2 года назад
This was so helpful, the MS documentation is severely lacking and I was looking for a way of doing this. I didn't look at your code until after i'd finished my own example of doing this in C# but it ended up being somewhat similar.
@bluehippotech
@bluehippotech 2 года назад
I hope you don't mind but i'm planning on doing a video on this as well :D
@MaykonAzevedo
@MaykonAzevedo 2 года назад
Amazing demo, thank you very much for that. Just a question, in the PowerShell command to add the app permission to the mailbox. Can I add a group with multiple email accounts?
@codewrecks
@codewrecks 2 года назад
Never tried, I've always give permission to individual mailboxes
@kevbehnke
@kevbehnke 2 года назад
Thank you for this. It saved me a ton of time and frustration.
@codewrecks
@codewrecks 2 года назад
Glad it helped!
@n17hero
@n17hero 2 месяца назад
I have been banging my head against the wall with one aspect of this that I can't seem to find a definitive answer on anywhere. Is access to the Office 365 Exchange Online API only available as part of a paid azure subscription? I am working on a learning side project, so am only using a basic azure subscription and that API does not come up for me.
@codewrecks
@codewrecks 2 месяца назад
You need to use the Azure subscription used by your Office 365 subscription.
@valiokaz
@valiokaz Год назад
hey, i`ll look like MS updated Azure, can`t find IMAP, there is no Office 365 Exchange Online in the selection.
@John-ok8ts
@John-ok8ts Год назад
I am getting "Internal error: {"error":"invalid_client","error_description":"AADSTS700025: Client is public so neither 'client_assertion' nor 'client_secret" when I use the link to login. When I try and access an account by passing in the email it says "No token available" which I assume is down to the first problem.
@KevinRodriguez-nm5hi
@KevinRodriguez-nm5hi 2 года назад
BROTHER, YOU ARE THE BEST!!! You oooh really helped me!! THANK YOU VERY MUCH!
@megangoller2456
@megangoller2456 Год назад
Thank you so much! You saved my day yesterday with this video! Blessings to you in all you do! YAY!
@cesarsantosvisballambis5469
I get the error not recognized "New-ServicePrincipal" on power shell .. what could be the reason bro ?
@codewrecks
@codewrecks Год назад
You are connected to the wrong azure tenant, or your account has not the right permission so you cannot create new principal
@Kannwal_Siingh
@Kannwal_Siingh Год назад
If i follow your video will this be able to work with outlook I mean i want to configure office365 email in outlook using imap
@codewrecks
@codewrecks Год назад
You do not need any special code to configure outlook, just open outlook and add your email and Outlook will be done everything for you.
@wnabbz
@wnabbz Год назад
This was very helpful, Thank you.
@jerryscally1510
@jerryscally1510 Год назад
Very informative; However the code portion is difficult to follow. What is the WellKnownConfigurationHandler; I have looked at the code and am getting lost. Thanks
@GianMariaRicci
@GianMariaRicci Год назад
I assume a basic knowledge of OIDC, well-known url are url that gives information about a special services, if you have an Identity Provider you usually append "/.well-known/openid-configuration" at the end of the url to have a json that gives you all the details of the provider (all the various url to grab token, etc etc).
@prasadruikar568
@prasadruikar568 Год назад
Do I have made this configuration to read the email from Outlook....please let me know asap😢
@codewrecks
@codewrecks Год назад
No, outlook supports oauth2 without any additional configuration
@mgsystemsdesarrolloweb4749
@mgsystemsdesarrolloweb4749 16 дней назад
Hi, thanks for the video, i get the token but then i have "Autheticantion Failed" response. I don't know what to do, i made all steps from the video except for the part of the PowerShell commands, i don't have permissions for that.
@codewrecks
@codewrecks День назад
You need to let someone that is administrator run the powershell, or it can't work
@sergioavendano6235
@sergioavendano6235 2 года назад
Hello, the source code/example from git do not have the option for 365-get-mail-client-flow in Swagger, do you know why?, any idea how can i get that option to test the functionality?, thanks
@badatgaems
@badatgaems 2 года назад
You probably don't have the right branch
@sergioavendano6235
@sergioavendano6235 2 года назад
@@badatgaems hi, yes wrong video, do you have any reference or example for how to authenticate with OAuth 2 to send an email (SMTP)?, thanks
@bluehippotech
@bluehippotech 2 года назад
@@sergioavendano6235 Microsoft SMTP doesn't support OAuth 2 yet unfortunately. Luckily SMTP won't be deprecated as IMAP will. Though you could switch to using an SMTP connector instead depending on your usecase if you really want something different.
@codewrecks
@codewrecks 2 года назад
@@sergioavendano6235 if you are interested I've code to use OAuth2 with SMTP too, even if standard Auth will not be deprecated
@sergioavendano6235
@sergioavendano6235 2 года назад
@@codewrecks Yes, please if possible send me the link of the example for smtp and OAuth2, thank you
@francescocordani6086
@francescocordani6086 Год назад
I did the post request and got the access_token but then I get "Authentication failed" when I try to access in IMAP through imap_open in php 7. How is that possible?
@codewrecks
@codewrecks Год назад
classic error is using the wrong claim, or maybe the XOAUT2 token is not created correctly by php library.
@AthelstanEngland
@AthelstanEngland Год назад
Do you have to have Azure for this to work? Don't know anything about Azure. We just have an Office365 account and a .NET service running on a server in the background which handles sending emails. This uses net.mail.smtp currently but that can't use OAUTH as far as I can see.
@gabrusalona
@gabrusalona Год назад
Can you update me if you found some solution? I have the same issue
@AthelstanEngland
@AthelstanEngland Год назад
@@gabrusalona hi did you see my reply? It seems to have been deleted for some reason?
@gabrusalona
@gabrusalona Год назад
@@AthelstanEngland I do
@weirddude8964
@weirddude8964 Год назад
Thanks! It's a very useful video!
@TheMagicalDisha111
@TheMagicalDisha111 2 года назад
Thank you, it works perfect!
@gouthamkrishna367
@gouthamkrishna367 2 года назад
Thanks a lot for your help. We were execatly looking for this.
@DX7Dev
@DX7Dev 2 года назад
You did a great job with this video.
@dilmidulanjali
@dilmidulanjali Год назад
I cannot find office 365 exchange online option in apis my organisation uses. Can you help?
@codewrecks
@codewrecks Год назад
You are probably connected to the wrong directory, you need to connect to Azure active directory connected to you O365 account
@mdaslamknl
@mdaslamknl Год назад
Excellent Keep it up Thanks
@hadisriatmono5713
@hadisriatmono5713 2 года назад
This is great, thank you!
@Hrishikeshdarshan
@Hrishikeshdarshan 2 года назад
hanks lot Sir.. You helping us..
@subhashree5052
@subhashree5052 2 месяца назад
Why I'm not getting APIs my organisation uses option not getting??
@codewrecks
@codewrecks 2 месяца назад
If I understood the question, probably is lack of permission on the tenant, or wrong tenant (you need to use tenant used by the office365 subscription)
@JurnRaaijmakers
@JurnRaaijmakers Год назад
Really great work, helped me a lot! Why oh why did MS make it so hard to manage a imap connection in office 365
@kirankumar-wf1eu
@kirankumar-wf1eu Год назад
This really helped us…works fab…thank u very much !!!
@SurajNair25
@SurajNair25 2 года назад
Wow! it's Amazing I did it well ! Perfect work !
@hatohadhatohad
@hatohadhatohad Год назад
Thanks for your video , get mail client flow works fine , but office get mail doesn't work , received this message error "No token available" Could you help me. Best regards
@codewrecks
@codewrecks Год назад
What do you mean with "office get mail"?
@tranysrafaelortegavalenzue3464
@tranysrafaelortegavalenzue3464 2 года назад
Thanks for this video. You helped me a lot
@DeepakChoudhary-yv7sx
@DeepakChoudhary-yv7sx 2 года назад
I have follow the same instructions that you provided still getting Authentication failed error , can you please provide suggestion
@codewrecks
@codewrecks 2 года назад
Well, usually it is Wrong permission on the app or Wrong claim in the request. Also try to run again powershell to give correct permissions to the app
@victormutisya5934
@victormutisya5934 2 года назад
Thanks for this. However, do you have / does anyone has a Java version of reading the mailbox?
@kevinlyman1
@kevinlyman1 Год назад
Thank you so much. This was fantastic. Great Job!!
@jiejiejie1
@jiejiejie1 2 года назад
why i can't find Office 365 Exchange Online in my APIs my orgainization uses?
@codewrecks
@codewrecks 2 года назад
As far as I know the most probably reason is: you are in a Azure Tenant that has no Office365 account (it happens if you have multiple tenant in Azure so you need to change directory, click on your avatar top right of the page and "change directory")
@mahmoudawd7846
@mahmoudawd7846 2 года назад
Thank you so much this helped a lot!!!! You saved my life
@simonkeen9368
@simonkeen9368 Год назад
Legendary. Thank you very much
@SuperShibbu
@SuperShibbu 2 года назад
Great! Can you also share the steps for applications connecting through EWS
@codewrecks
@codewrecks 2 года назад
Sorry but I do not know/use the EWS API, I needed code to use basic IMAP / SMTP communication but I think that the process is the very same, once you obtained the token usually you set into a special header stackoverflow.com/questions/22229996/basic-http-and-bearer-token-authentication
@murugeshs4248
@murugeshs4248 Год назад
Amazing! It saved my day! Thanks a lot. :)
@jaypatadia5902
@jaypatadia5902 Год назад
im not getting option for office exchange in api permission how to configure that
@codewrecks
@codewrecks Год назад
Probably that azure account is not connected to an Office 365 account, so there is no exchange api because there is no exchange.
@isaacbenjaminmoralestrejo1822
Can you post the link of your previous video please?
@codewrecks
@codewrecks Месяц назад
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Q660AYVZM0Y.html Sorry for late response
@emilmalinov2893
@emilmalinov2893 2 года назад
Brilliant, saved me so much time.
@codewrecks
@codewrecks 2 года назад
I'm happy that the video was useful.
@gouthamkrishna367
@gouthamkrishna367 2 года назад
Can you please make a similar video for OAUTH implementation for SMTP Protocol to send mails. Somehow it is not working for us.
@codewrecks
@codewrecks 2 года назад
I'm planning to record it in the next days, it is really similar to the other one, but it could be useful for people (actually SMTP with basic auth is not going to be deprecated)
@codewrecks
@codewrecks 2 года назад
Hi actually I have the code running (I had almost three days with no connection so I had problem running the code) You can try develop branch in this repository github.com/alkampfergit/DotNetCoreOauth2/tree/develop it has a super basic HTML page answering at sample-oauth2 url. Remember also that SMTP is available only with code auth flow (the one requiring the user to click authorization link)
@codewrecks
@codewrecks 2 года назад
I've made a video with a BIG recap as well as the code for SMTP ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-hOgvTDKKgnY.html
@enzourbinati2702
@enzourbinati2702 10 месяцев назад
Thank you very much
@geodezijasmer338
@geodezijasmer338 2 года назад
it worked! thank you so much!!
@toddmueller
@toddmueller 2 года назад
I followed your example and have run into this issue. MailKit.Security.AuthenticationException: 'Authentication failed.' Has anyone come access this issue?
@codewrecks
@codewrecks 2 года назад
That is a generic error, it could happen if the token is not valid or the application has not the correct permissions. Sadly enough, the remote server does not tells you what it does not like and throws a generic auth error (not giving further details)
@toddmueller
@toddmueller 2 года назад
@@codewrecks oauth.IsAuthenticated = false. Any tips you can offer to help track this down? Thanks for the help!
@ruzannamartirosyan351
@ruzannamartirosyan351 Год назад
@@toddmueller Did you manage to solve the "Authentication Failed" issue? I faced the same problem.
@toddmueller
@toddmueller Год назад
@@ruzannamartirosyan351 Not yet. I'm still talking to Microsoft about it. More than likely it's a config issue. Once I have more details, I'll share.
@nicoloscarpa1492
@nicoloscarpa1492 Год назад
Sooo helpful! Thank you!
@haroonhikmath3681
@haroonhikmath3681 2 года назад
yo bro, really thankya. Big respect
@username_6948
@username_6948 11 месяцев назад
THANKS!
@halkagyaani8919
@halkagyaani8919 2 года назад
U BEST!!!
@NikitaBrattsev
@NikitaBrattsev 2 года назад
Thank you so much, you saved my day!
@leepaulalexander
@leepaulalexander Год назад
Perfect!
@impaksensasi5456
@impaksensasi5456 2 года назад
Works well!! DANKEEE
@amsaluazanaw77
@amsaluazanaw77 2 года назад
For once, the software is actually really useful
@MrNoseaj
@MrNoseaj 2 года назад
I dоwnloaded everything is okay
@bosibsoito1941
@bosibsoito1941 2 года назад
I'm unstoppable I'm a Porsche with no brakes
@codewrecks
@codewrecks 2 года назад
0_O
@ous7734
@ous7734 Год назад
🥳
@zdrgdr
@zdrgdr Год назад
MS again doing something without doing their homework...
@PA-lf8sd
@PA-lf8sd 2 года назад
How do you access POP3 after Oct 2022 if you don't have an Azure account...?
@codewrecks
@codewrecks 2 года назад
If you have an Office 365 account you have your Azure Active directory associated to that subscription.
@PA-lf8sd
@PA-lf8sd 2 года назад
@@codewrecks Cool. I think I've found it... But...why have MS made it so bloody complicated...!? Very little of the nonsense it asks for makes much sense to me...
@jamesinger4540
@jamesinger4540 2 года назад
HI @CodeWrecks, could I get the SMTP OAUth2 sample code as well please, let me know hwo you want to send that code.
@codewrecks
@codewrecks 2 года назад
You can find code here github.com/alkampfergit/DotNetCoreOauth2/tree/develop just look for the sample-oauth2 controller. Video is coming.
@codewrecks
@codewrecks 2 года назад
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-hOgvTDKKgnY.html
@nilsonchagas
@nilsonchagas Год назад
Well, I am freezer in this point the message: New-ServicePrincipal: |Microsoft.Exchange.Configuration.Tasks.ThrowTerminatingErrorException|ExternalDirectoryObjectIdRaw: The length of the property is too long. The maximum length is 256 and the length of the value provided is 1269. Someone could help me?
@GianMariaRicci
@GianMariaRicci Год назад
What is the value of $MyApp.ObjectId? It seems that it is not what it expected, because is really too long.
@saitejaveeraganti8485
@saitejaveeraganti8485 2 года назад
This is great, thank you!
@michael200kg
@michael200kg 2 года назад
Wow it is really helpful! Thanks!
@codewrecks
@codewrecks 2 года назад
Glad it was helpful!
Далее
PUBG Mobile СТАЛ ПЛАТНЫМ! 😳
00:31
Просмотров 219 тыс.
OAuth 2.0 and OpenID Connect (in plain English)
1:02:17
Oauth 2.0 Client Credential Flow | Microsoft Graph
10:37
Office 365 IMAP OAuth With C#
7:04
Просмотров 22 тыс.
Configuring SMTP Relay
20:41
Просмотров 4 тыс.
An Illustrated Guide to OAuth and OpenID Connect
16:36
Просмотров 599 тыс.
Google OAuth with curl: A Complete Tutorial
17:02
Просмотров 25 тыс.