Authenticating client with office 365/SharePoint online
Asked Answered
T

2

5

I have a client application which consumes SharePoint web service (list.asmx). Recently SharePoint is migrated to SharePoint Online. Now authentication is failing.

This might be because authentication mechanism is different in SharePoint Online. I referred the article http://www.wictorwilen.se/Post/How-to-do-active-authentication-to-Office-365-and-SharePoint-Online.aspx for doing the authentication. However for some reason I am getting Authentication error now.

Please note I do not want authentication window to pop-up, as my client is a service.

Can anybody please give me some pointer/sample working application on how to do authentication with SharePoint Online?

Atul Sureka

Tabescent answered 6/1, 2014 at 13:1 Comment(0)
C
10

You can use the SharePoint Client Object Model to login into SharePoint online. If you use the username and password for authentication, instead of OAuth method, there's no authentication window pops up.

As how to do it, please refer this article.

Cayman answered 6/1, 2014 at 16:59 Comment(4)
@Cayman i am bit stuck with that, i am trying to authenticate using office365 and trying to get address of his/her sharepoint site and their whole directory in it. can i will be successful ?Dittany
@KhawajaAsim, you mean you have the user name and password, you want to get all the site collections under the root?Cayman
@Cayman I just only have the authentication token of office365 api after successful login from popup(login.microsoftonline.com). How can i get the user sharepoint host URL ?Dittany
@KhawajaAsim, based on my knowledge, you can only use powershell command to do that: learn.microsoft.com/en-us/powershell/msonline/v1/get-msoldomainCayman
E
14

SharePoint Online (SPO) uses claims-based authentication mode. Microsoft released SharePoint Online Client Components SDK which contains SharePointOnlineCredentials class that could be utilized for SharePoint Web Services authentication in SPO.

How to authenticate SharePoint Web Services in SharePoint Online (SPO)

The following example demonstrates how to retrieve authentication cookies:

private static CookieContainer GetAuthCookies(Uri webUri, string userName, string password)
{
    var securePassword = new SecureString();
    foreach (var c in password) { securePassword.AppendChar(c); }
    var credentials = new SharePointOnlineCredentials(userName, securePassword);
    var authCookie = credentials.GetAuthenticationCookie(webUri);
    var cookieContainer = new CookieContainer();
    cookieContainer.SetCookies(webUri, authCookie);
    return cookieContainer;
}

Example

string sourceUrl = "https://contoso.sharepoint.com/Documents/SharePoint User Guide.docx";
string destinationUrl = "https://contoso.sharepoint.com/Documents/SharePoint User Guide 2013.docx";
FieldInformation[] fieldInfos;
CopyResult[] result;
byte[] fileContent;
using(var proxyCopy = new Copy())
{
     proxyCopy.Url = webUri + "/_vti_bin/Copy.asmx";
     proxyCopy.CookieContainer = GetAuthCookies(webUri, userName, password);

     proxyCopy.GetItem(sourceUrl,out fieldInfos,out fileContent);
     proxyCopy.CopyIntoItems(sourceUrl,new []{ destinationUrl}, fieldInfos, fileContent, out result);
 }

References

Egeria answered 18/2, 2015 at 14:26 Comment(0)
C
10

You can use the SharePoint Client Object Model to login into SharePoint online. If you use the username and password for authentication, instead of OAuth method, there's no authentication window pops up.

As how to do it, please refer this article.

Cayman answered 6/1, 2014 at 16:59 Comment(4)
@Cayman i am bit stuck with that, i am trying to authenticate using office365 and trying to get address of his/her sharepoint site and their whole directory in it. can i will be successful ?Dittany
@KhawajaAsim, you mean you have the user name and password, you want to get all the site collections under the root?Cayman
@Cayman I just only have the authentication token of office365 api after successful login from popup(login.microsoftonline.com). How can i get the user sharepoint host URL ?Dittany
@KhawajaAsim, based on my knowledge, you can only use powershell command to do that: learn.microsoft.com/en-us/powershell/msonline/v1/get-msoldomainCayman

© 2022 - 2024 — McMap. All rights reserved.