The question is very straight forward.

Is it possible to use Username and Password as a Plain text to get Office 365 Groups and users in c# code using Microsoft Graph API or any other API?

If yes, then how? I need to develop an application where I need to fetch the Office 365 Groups and Users and display it to the Non Admin Users too.

1 Answer 1


We can use SharePoint Online CSOM(Download SharePoint Online Client Components SDK) to achieve it. The code below for your reference.

string targetSiteURL = @"https://xxx.sharepoint.com/sites/lz";

//set user login name and passsword 
var username = "[email protected]";
var password = "Password";

var securePassword = new SecureString();
foreach (char c in password){securePassword.AppendChar(c);}

SharePointOnlineCredentials onlineCredentials = new SharePointOnlineCredentials(username, securePassword);

ClientContext ctx = new ClientContext(targetSiteURL);
ctx.Credentials = onlineCredentials;

GroupCollection groups = ctx.Web.SiteGroups;

foreach(Group group in groups)
    Console.WriteLine("Group Name:"+group.Title);             
    foreach(User user in group.Users)
        Console.WriteLine("   UserName:"+user.Title);
  • I guess you interpreted the question wrong. I have specified that I need to access Office 365 Groups, Not SharePoint Groups. I tagged the SharePoint Online because I want to display the Office 365 groups in SharePoint WebPart.. Jan 5, 2018 at 3:56

Your Answer

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

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