Simple Office365 authentication

Use Office365 account login for your application

  • Share

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("https://outlook.office365.com/api/v1.0/me/").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.

            try
            {
                HttpResponse<string> response = Unirest.get("https://outlook.office365.com/api/v1.0/me/").basicAuth(username, password).asJson<string>();
                return response.Code == 200;
            }
            catch (Exception ex)
            {
                return false;
            }
    
Note

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

References

  • Share

Disclaimer

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.

Comments for this article

comments powered by Disqus