question

developersp1-9584 avatar image
0 Votes"
developersp1-9584 asked sameralisaleh-6318 published

.NET Core SharePointOnlineCredentials class

I'm using the latest CSOM library which should be supported .NET Core solution.
However, I can't find SharePointOnlineCredentials class when coding.

What's the required step to use it in .NET Core solution ?

Thanks for any help please :)

office-sharepoint-online
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

trevorseward avatar image
0 Votes"
trevorseward answered sameralisaleh-6318 published

It has been removed. You shouldn't be using username/pass to access services via API. See https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/using-csom-for-dotnet-standard#using-modern-authentication-with-csom-for-net-standard for more information.

· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Respectfully I think you've missed the mark.

I agree with trying to keep passwords out of source codes, however, I'd like to call your attention to the current problem I have: I'm a guest on someone else's sharepoint - lets call them BigHealthCompany - they wont let me register a AAD ID and even if they did it'd take weeks for the request to be processed. All I want to do is use my credentials to have a script that automatically takes files out of sharepoint and puts them into a directory and processes them... Yes, in an ideal work you'd use OneDrive and sync the directory then use a FileSystemWatcher; but that also is broken.

So here we are trying to keep from having to use Selenium and ChromeWebDriver from logging in and checking the directory manually.... Oh well -- time is up -- good news for me is I already had Selenium in the project I was working on...

0 Votes 0 ·

You won't be able to use username/password since you need to go through Modern Auth. You need CID/Secret or something that will otherwise run interactively, especially because you lack control over the tenant.

0 Votes 0 ·

I ended up making a .net framework 4.8 service that does the same thing OneDrive is supposed to do, using sharepointonlinecredentials. Works great.

1 Vote 1 ·

So thank you microsoft for making life so much complicated yet again. you did not disappoint. so basically you are asking me to replace one line of code with much more and asking me to go and configure things in azure WOW

0 Votes 0 ·
BakerKong-MSFT avatar image
0 Votes"
BakerKong-MSFT answered BakerKong-MSFT commented

Hi developersp1-9584,

It's not possible to use SharePointOnlineCredentials in CSOM for .NET Standard. Instead, it's recommended to use OAuth to acquire an access token.
Here is a blog that demonstrates how to use OAuth 2.0 Resource Owner Password Credentials for fetching the token and use the token in CSOM:

Best Regards,
Baker Kong

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi developersp1-9584,

Regarding this issue, Is there any other concern? Please feel free to talk with us if you have further questions. And if the above info is helpful to this issue, you can mark it as an answer so that others who stuck in similar issues could get answered quickly

Thanks
Baker Kong

0 Votes 0 ·
MarcMoraGibert-5099 avatar image
0 Votes"
MarcMoraGibert-5099 answered BakerKong-MSFT commented

Hi, there's a way to get Sharepoint Authentication Cookie with this new Authentication model? With old SharepointOnlineCredentials , we used GetAuthenticationCookie method to get this, but with new system I don't know how can I get this. Is it posible?

Thanks!

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @MarcMoraGibert-5099,

Cookie-based auth is not supported in .net core CSOM as it uses OAuth authentication. Below blog shares the behind requests of SharePointOnlineCredentials, you may have a look. Or you can trace the request using Fiddler

We can convert the steps in above blog to C# code:

Best Regards,
Baker Kong

0 Votes 0 ·

Hi @MarcMoraGibert-5099 & @developersp1-9584 ,

Regarding this issue, we have not heard from you for some time. Do you have any other questions? If the above info is helpful to this issue, it would be appreciated if you can mark it as an answer so that others who stuck in similar issues could get answered quickly.

Thanks
Baker Kong

0 Votes 0 ·