Simple Office365 authentication

Use Office365 account login for your application

With so many online and cloud based services, adding one more additional account for your application adds additional complexity level for your users since they will have to manage one more account and remember one more password.

Microsft ASP.NET comes with pretty nice built in provides for social networks, but for office usage social networks are not so convenient to be used.

So introducing Office365 account authentication toy your application might have a lot of sense. Luckily for us, Office365 allows pretty simple authentication with their exposed API endpoints.

To make code simplier I used Unirest API nuget package. It is a .NET port of Java famous Unirest package.

                HttpResponse<string> response = Unirest.get("").basicAuth(username, password).asJson<string>();

All we need to check is the response code returned for the request. User credentials are corrent only if the response status code is equeal to 200.

                HttpResponse<string> response = Unirest.get("").basicAuth(username, password).asJson<string>();
                return response.Code == 200;
            catch (Exception ex)
                return false;

This is the simplest but not the best way of using Office365 authentication in your application. Also secured connection using SSL/HTTPS should be used in order not to compromise login credentials



Purpose of the code contained in snippets or available for download in this article is solely for learning and demo purposes. Author will not be held responsible for any failure or damages caused due to any other usage.

About the author


Dejan is a passionate Software Architect/Developer. He is highly experienced in .NET programming platform including ASP.NET MVC and WebApi. He likes working on new technologies and exciting challenging projects

CONNECT WITH DEJAN  Loginlinkedin Logintwitter Logingoogleplus Logingoogleplus


read more


read more

Umbraco CMS

read more


read more

Comments for this article