I'm trying to build an MVC ASP.NET appthat read in my sharepoint online a list I included in MVC the Azure Active directory login, but I don't understand how to pass the credential to sharepoint site. I use the Stefano's tutorial to build my app Thank you …

1 Answer 1


here is the function that will return authenticated ClientContext object:

Sample Code:

public ClientContext Auth(String uname, String pwd,string siteURL) {
ClientContext context = new ClientContext(siteURL);
Web web = context.Web;
SecureString passWord = new SecureString();
foreach (char c in pwd.ToCharArray()) passWord.AppendChar(c);
context.Credentials = new SharePointOnlineCredentials(username, passWord);
    Console.WriteLine("Olla! from " + web.Title + " site");
    return context;
catch (Exception e) {
    Console.WriteLine("Something went wrong in Auth Module" + e);
    return null; 

Ref : https://coderwall.com/p/ho2uwq/authentication-in-sharepoint-2013-using-c-csom-client

Required dll: https://www.nuget.org/packages/Microsoft.SharePointOnline.CSOM

Note: best approach to store your username and password would be web.config file of you MVC project.


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.