2
votes

I am trying to access Microsoft Office 365 Planner using CSOM and Azure App. Whenever I try to access planner using group Id i am getting the below error:

401 - Unauthorized: Access is denied due to invalid credentials. You do not have permission to view this directory or page using the credentials that you supplied.

I have given the required permissions to Azure Graph api. Application - Read Groups All, Read and Write Groups All. Delegated - Tasks.ReadWrite

Below is the sample code that i am using:

//Querying plans in current group await 
graphClient.Groups[groupId].Planner.Plans.Request().GetAsync();

Is there any option to achieve this. I need to access the planner and need to create Buckets and plans based on Office 365 group.

Any help is much appreciated. Thanks in advance.

1

1 Answers

0
votes

You should be using Microsoft Graph rather than Azure AD Graph API.

https://docs.microsoft.com/en-us/graph/planner-concept-overview

Also, you need to authenticate with your user credentials to access the Planner. You can change the GetAccessToken method to authenticate this way (example from linked blog).

private async Task<string> GetAccessToken(string resourceId, string userName, string password)
{
    try
    {
        var authority = ConfigurationManager.AppSettings["ida:AuthorizationLoginUri"] + ConfigurationManager.AppSettings["ida:TenantId"];
        var authContext = new AuthenticationContext(authority);
        var credentials = new UserPasswordCredential(userName, password);
        var authResult = await authContext.AcquireTokenAsync(resourceId, ConfigurationManager.AppSettings["ida:ClientIdNativeClient"], credentials);

        // Get the result
        return authResult.AccessToken;
    }
    catch (Exception ex)
    {
       // TODO: handle the exception
       return;
    }

You need to also ensure that your app is registered properly in the portal. Please check out this helpful blog that shows how to get past the error you described when accessing the planner: https://karinebosch.wordpress.com/2017/12/18/microsoft-graph/