Sharepoint - Access Documents - SSO

%3CLINGO-SUB%20id%3D%22lingo-sub-1321456%22%20slang%3D%22en-US%22%3ESharepoint%20-%20Access%20Documents%20-%20SSO%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1321456%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20using%20the%20Sharepoint%20CSOM%20API%20to%20access%20Sharepoint%20Online%20and%20access%2Fdownload%2Fupload%20files.%3C%2FP%3E%3CP%3ESharePointOnlineCredentials%20is%20used%20to%20set%20up%20the%20credentials%20(username%2C%20password).%20Is%20there%20a%20way%20to%20use%20the%20currently%20signed%20in%20windows%20user%20(instead%20of%20providing%20the%20username%20and%20password)%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20following%20piece%20of%20code%20is%20used%20to%20get%20a%20list%20of%20files.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EClientContext%20ctx%20%3D%20new%20ClientContext(siteUrl)%3B%3CBR%20%2F%3E%2F%2F%20Use%20UserName%2FPassword%20to%20access%20the%20sharepoint%3CBR%20%2F%3Ectx.Credentials%20%3D%20new%20SharePointOnlineCredentials(%22phil.collins%40singer.com%22%2C%20theSecureString)%3B%3C%2FP%3E%3CP%3EFileCollection%20files%20%3D%20ctx.Web.GetFolderByServerRelativeUrl(folderPath).Files%3B%3CBR%20%2F%3Ectx.Load(files)%3B%3CBR%20%2F%3Ectx.ExecuteQuery()%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Visitor

Hi,

 

I am using the Sharepoint CSOM API to access Sharepoint Online and access/download/upload files.

SharePointOnlineCredentials is used to set up the credentials (username, password). Is there a way to use the currently signed in windows user (instead of providing the username and password)?

 

The following piece of code is used to get a list of files.

 

ClientContext ctx = new ClientContext(siteUrl);
// Use UserName/Password to access the sharepoint
ctx.Credentials = new SharePointOnlineCredentials("phil.collins@singer.com", theSecureString);

FileCollection files = ctx.Web.GetFolderByServerRelativeUrl(folderPath).Files;
ctx.Load(files);
ctx.ExecuteQuery();

0 Replies