Azure AD - Office365APIs. Check if connected user is global admin without admin consent scopes

Benoit Patra

I have a mutlitenant Office365 web application that authenticates users with an Authorization code flow (my server does the requests to the APIs) secured by Azure AD on OAUTH/OpenIdConnect.

We use Microsoft.Owin.Security.OpenIdConnect, Version=3.0.0.0 and Azure Active Directory ADAL.NET client with Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.19.0.0 following this sample.

In my Azure AD application manifest, I use only scopes without admin consent.

However, I would like to know if the currently connected user is an Office 365 Global Admin of the tenant.

I checked the accepted answer here. That basically reads the response at <graphurl>/me/memberOf However, it is not acceptable in my situation. Following this reference, all the required scopes are "Admin consent" scopes.

I tried different approaches: using the System.Web.Security.Roles.GetRolesForUser(), looking in ClaimsPrincipal.Current and finally examining carefully the parsed JWT to see if there is an info on the Office365 roles of the connected user. All without success.

Can you provide a way to know the current user administration roles within the Office 365 tenants with an application declared with no admin consent scopes?

Remark: This question is more or less related to this one but the requirements are less strong: we only want to see if the current user is a Global Admin.

Jeffrey Chen

Can you provide a way to know the current user administration roles within the Office 365 tenants with an application declared with no admin consent scopes?

For multi-tenant application, accessing to directory data requires the admin consent.

But once administrators give the consent for the application, all users within the organization will be allowed to use the application (no need to consent).

Add consent url parameter "prompt=admin_consent":

    public ActionResult AdminConsentApp()
    {
        string strResource = Request.QueryString["resource"];
        string strRedirectController = Request.QueryString["redirect"];

        string authorizationRequest = String.Format(
            "https://login.windows.net/common/oauth2/authorize?response_type=code&client_id={0}&resource={1}&redirect_uri={2}&prompt={3}",
                Uri.EscapeDataString(SettingsHelper.ClientId),
                Uri.EscapeDataString(strResource),
                Uri.EscapeDataString(String.Format("{0}/{1}", this.Request.Url.GetLeftPart(UriPartial.Authority).ToString(), strRedirectController)),
                Uri.EscapeDataString("admin_consent")
                );

        return new RedirectResult(authorizationRequest);
    }

For more details, you can reference the sample project O365-WebApp-MultiTenant.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

admin_consent for openid connect and dynamic scopes

From Dev

Bypassing scopes consent screen for non-admin users

From Dev

Cannot see Azure AD even having role as global admin and co-admin on its subscription

From Dev

Check if user is admin PHP

From Dev

Check if the end user is admin

From Dev

ADAL user consent triggered even when admin has already consented

From Dev

Alternative to Groups.ReadBasic.All - access Groups without Admin consent

From Dev

Check if user is admin when loggin in

From Dev

How I check if the user is an ADMIN

From Dev

Active Admin filters and scopes

From Dev

Active Admin filters and scopes

From Dev

Microsoft graph APIs for oneDrive data access is not working with admin consent

From Dev

Multi Tenant Azure AD non admin login

From Dev

Access denied office 365 / SharePoint online with Global Admin account

From Dev

Scopes as filters in rails_admin

From Dev

How to check if currently logged in user is admin or not

From Dev

Check if user is an admin by username or email only

From Dev

How to check whether admin or user is logged in odoo

From Dev

PHP function to check whether a user is admin or not

From Dev

Check if user is admin when logging in to PHP website

From Dev

Creating user account without admin or control panel

From Dev

CouchDB add user without predefined admin

From Dev

Log in user without giving access to admin interface

From Dev

Remove AD user from domain and convert it to local admin account

From Dev

How to create ad-hoc network without admin rights

From Dev

Azure AD Sync Error - Existing Admin Role Conflict

From Dev

How do I check if a user has 2-factor authentication enabled via Google Admin SDK APIs

From Dev

Office365 - Application authentication with no user consent

From Dev

Azure AD Login Without user browser redirect?

Related Related

  1. 1

    admin_consent for openid connect and dynamic scopes

  2. 2

    Bypassing scopes consent screen for non-admin users

  3. 3

    Cannot see Azure AD even having role as global admin and co-admin on its subscription

  4. 4

    Check if user is admin PHP

  5. 5

    Check if the end user is admin

  6. 6

    ADAL user consent triggered even when admin has already consented

  7. 7

    Alternative to Groups.ReadBasic.All - access Groups without Admin consent

  8. 8

    Check if user is admin when loggin in

  9. 9

    How I check if the user is an ADMIN

  10. 10

    Active Admin filters and scopes

  11. 11

    Active Admin filters and scopes

  12. 12

    Microsoft graph APIs for oneDrive data access is not working with admin consent

  13. 13

    Multi Tenant Azure AD non admin login

  14. 14

    Access denied office 365 / SharePoint online with Global Admin account

  15. 15

    Scopes as filters in rails_admin

  16. 16

    How to check if currently logged in user is admin or not

  17. 17

    Check if user is an admin by username or email only

  18. 18

    How to check whether admin or user is logged in odoo

  19. 19

    PHP function to check whether a user is admin or not

  20. 20

    Check if user is admin when logging in to PHP website

  21. 21

    Creating user account without admin or control panel

  22. 22

    CouchDB add user without predefined admin

  23. 23

    Log in user without giving access to admin interface

  24. 24

    Remove AD user from domain and convert it to local admin account

  25. 25

    How to create ad-hoc network without admin rights

  26. 26

    Azure AD Sync Error - Existing Admin Role Conflict

  27. 27

    How do I check if a user has 2-factor authentication enabled via Google Admin SDK APIs

  28. 28

    Office365 - Application authentication with no user consent

  29. 29

    Azure AD Login Without user browser redirect?

HotTag

Archive