I created a Web app using Office365 preview APIs to to consume Office 365 Services with full permissions to services(including UserProfile.Read permission)

I am trying to get all user profiles using the REST API.

I tried the below url on postman(chrome app) by passing access token in headers.


I was asked to enter the admin's credentials.

So how to get user profiles using access token but not by giving credentials.

Any help would be greatly appreciated

1 Answer 1


Since you are building application using Office 365 APIs Preview, Azure AD Graph API could be utilized for getting user details (Users and Groups service on the picture below).

enter image description here

The following example demonstrates how to retrieve users using Azure AD Graph API (excerpt from ASP.NET MVC App):

public static class UserManager
    const string ServiceResourceId = "https://graph.windows.net/";
    static readonly Uri ServiceEndpointUri = new Uri("https://graph.windows.net/");
    static DiscoveryContext _discoveryContext;

    public static async Task<IEnumerable<IUser>> GetUsers()
        var client = await EnsureClientCreated();
        var userResults = await client.DirectoryObjects.OfType<IUser>().ExecuteAsync();
        var allUsers = new List<IUser>();

            userResults = await userResults.GetNextPageAsync();
        } while (userResults != null);

        return allUsers;

    public static async Task<AadGraphClient> EnsureClientCreated()
        if (_discoveryContext == null)
            _discoveryContext = await DiscoveryContext.CreateAsync();

        var dcr = await _discoveryContext.DiscoverResourceAsync(ServiceResourceId);

        return new AadGraphClient(new Uri(ServiceEndpointUri, dcr.TenantId), async () =>
            return (await _discoveryContext.AuthenticationContext.AcquireTokenByRefreshTokenAsync(new SessionCache().Read("RefreshToken"), new Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential(_discoveryContext.AppIdentity.ClientId, _discoveryContext.AppIdentity.ClientSecret), ServiceResourceId)).AccessToken;

Key points:

  • The Azure Active Directory Graph API (AadGraphClient Class) is used for
    getting a user’s detailed properties
  • ClientCredential Class is used for authentication in O365 by providing client id and secret.


public class O365UserManagementController : Controller
    public async Task<ActionResult> Index()
            var allUsers = await UserManager.GetUsers();
            return View(allUsers);
        catch (RedirectRequiredException ex)
            return Redirect(ex.RedirectUri.ToString());
  • 1
    Thanks @Vadim, Using AD Graph API, I can get all the properties except user's personal site url. How to get the personal site url of an user using REST API ?
    – user31420
    Sep 8, 2014 at 5:48
  • @user31420 Were you successful in getting personal site url through the REST API? Jan 4, 2016 at 9:22
  • @SyedMauzeRehan I got it working with help of the this link msdn.microsoft.com/en-us/library/office/…
    – user31420
    Jan 5, 2016 at 18:01
  • Yes indeed. The problem with my case is that http://<site url>/ needs to be figured out. Discovery service is not a option for me. How can I get this Site URl to make the API call to the begin with? Jan 5, 2016 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.