0
votes

I'm integrating an asp.net web application with office 365 email using o365 api client library.

I want to sign in using the c# code not by showing the Microsoft UI sign in page(https://login.microsoftonline.com/login.srf).

If I provide username/password for an user and if the username/password is correct then it should authenticate the user to see the office 365 mails of the asp.net web application.

Thanks in advance.

1
Do do want to login to O365 without login page or just send some notification emails from the web server?Nan Yu
I want to login to O365 without login page and access the office 365 mailbox which I already developed in my ASP.Net web application using O365 API Client library. Currently I'm using the below code to check whether user logged in or not. if (!Request.IsAuthenticated) { HttpContext.Current.GetOwinContext().Authentication.Challenge( new AuthenticationProperties { RedirectUri = "/" }, OpenIdConnectAuthenticationDefaults.AuthenticationType); }Gopal Biswas

1 Answers

0
votes

The purpose of OAUTH is to protect both your and your users. As soon as you get into the business of storing credentials, you own responsibility for securing those credentials.

I assume you are looking to access a user's data via a backend process. This workflow requires the "offline_access" scope. Offline does not mean "disconnected from the internet" but rather that the end-user is "offline" from your app (not able to interact with a UX).

You should be executing an OAUTH Code Grant workflow and adding "openid" and "offline_access" to your scopes. This will give you both an id_token that can be used to hit the Office APIs as well as a refresh_token that you can use to get a new id_token when the existing token expires. Refresh tokens can be used even if the end-user is off line (there is no UX involved).

Once you have an id_token and refresh_token, you can use these values to interact with O365 on the end-user's behalf. A common example would be syncing calendars. The first time a user will need to authenticate and configure (i.e. which calendars do they want to sync). From then on, your sever uses the id_token and refresh_token to operate without the user being online (this the term "offline_access").