Microsoft Graph API: Insufficient privileges to complete the operation.

I was playing around with Django and django-allauth to use existing authentication providers and do not need to hassle with my own user management.

When trying to implement a Microsoft login, I was getting the following error:

Insufficient privileges to complete the operation.

Sometimes you are not getting the actual error message, you are only seeing "Social Network Login Failure". To figure out more, overwrite the Django template by adding a socialaccount folder with a template authentication_error.html. You can now add the following lines of code in your template to see the real error:

{% extends "socialaccount/base.html" %}

{% load i18n %}

{% block head_title %}{% trans "Social Network Login Failure" %}{% endblock %}

{% block content %}
<h1>{% trans "Social Network Login Failure" %}</h1>

<p>{% trans "An error occurred while attempting to login via your social network account." %}</p>

    Code: {{ auth_error.code }}, Error: {{ auth_error.exception }}
{% endblock %}

To solve this you need to grant access to your application. If you are the admin, you can do it in your API permission section:

If you are not the admin, an admin has to approve it. For this send the following URL to your admin:{tenant_ID_HERE}/adminconsent?client_id={CLIENT ID HERE}