2

So I need to create an Application that will connect to SharePoint Online with a service account Using SSO.

i've downloaded the authentication manager but i don't see any way to code SSO Credentials.

is there a way to have an Service Account or an application impersonating an user?

should i ask my company to provide me with an API to connect through or sso and get the authentication cookie?

  • Can I use the step to login sharepoint online on browser? Thank you. – Bryant Nov 9 '18 at 2:19
2
+300

Instead of using a service account with username and password, would suggest that you connect and authenticate to SharePoint online by using Client Id and Secret according to this documentation.

It will be a one-time setup with the below mentioned steps:

1) Go to your SharePoint online site collection

2) Enter the URL as https://<tenant-name>.sharepoint.com/sites/test/_layouts/15/appregnew.aspx

3) On that page, we will generate the Client ID and Secret

4) Add the Title as some "SSO Auth"

5) Enter App domain as localhost and Redirect URL as https://localhost.

6) Then click on create. Save the client ID and Secret in a local file or notepad. It should look something like:

enter image description here

Once the above step is done, go to https://<tenant-name>.sharepoint.com/sites/test/_layouts/15/appinv.aspx

1) In the App id, enter the Client Id that we generated in the previous step and then click on [lookup]

2) In the Permission Request XML section, enter the below XML code:

<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl" />
</AppPermissionRequests>

3) Click on [Create]. See below screenshot

enter image description here

4) After that, it will redirect you and on that page, click on the [Trust It] button.

Once the above steps are done, in your application, download the SharePoint PnP core package from nuget as below:

enter image description here

After that, you can use PnP's Authentication Manager's method to authenticate as below:

var clientID = "<your-client-id>";
var clientSecret = "<your-client-secret>";

var authManager = new OfficeDevPnP.Core.AuthenticationManager();
ClientContext clientContext = authManager.GetAppOnlyAuthenticatedContext("https://<tenant-name>.sharepoint.com/sites/test/", clientID, clientSecret);
  • Thank you Sheth, this work like a Charm ! is there a limit or expiration for the Registered app client ID and Client Secret? – Mike Jul 3 '18 at 15:51
  • Client secrets expire after 1 year. After that you renew them which can be extended to 3 years and so on. You can refer this link – Gautam Sheth Jul 3 '18 at 15:55
  • 1
    Also, there is another way to connect to SharePoint online using App Only Permissions and Certificate authentication which can be valid upto 30 years. Its a bit more complicated but you can check out this sample. Let me know if need the CSOM C# equivalent for this sample ! – Gautam Sheth Jul 3 '18 at 16:41
  • can we do same in powershell also?? @GautamSheth – Rajesh Joshi Jun 10 at 11:56
  • 1
    @RajeshJoshi - you can do that via PnP PowerShell as mentioned here – Gautam Sheth Jun 13 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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