0

I am trying to authenticate to SharePoint site using the authentication.asmx web service. The code is as below.

  public bool Authenticate()
  {
    String username = "......"; 
    String password = "......";
    Cookie _authCookie;
    CookieContainer _cookieContainer;


    AuthService.Authentication authentication = new AuthService.Authentication();
    authentication.Url = "<web_url>/_vti_bin/Authentication.asmx";
    authentication.CookieContainer = new CookieContainer();
    authentication.AllowAutoRedirect = true;
    authentication.PreAuthenticate = true;
    AuthService.LoginResult loginResult = authentication.Login(username, password);

    _authCookie = new Cookie();

    if (loginResult.ErrorCode == AuthService.LoginErrorCode.NoError)
    {
        CookieCollection cookies = authentication.CookieContainer.GetCookies(new Uri(authentication.Url));
        _authCookie = cookies[loginResult.CookieName];
        _cookieContainer = new CookieContainer();
        _cookieContainer.Add(_authCookie);
        return true;
    }
    else
        return false;
  }

But I am getting an error "PasswordNotMatch" in ErrorCode, even though the username and password I am entering is correct.

The AuthService is a Service Reference to the authentication.asmx web service

Did anybody solve the issue?

1 Answer 1

0

the question has been answered before, look at ashish answer as it implements your code. I think the area your going wrong is in the cookie part.

Windows authentication with SharePoint Web Services via SOAP

the code is for list authentication but a slight alteration would give you site authentication. The principal is the same!

EDIT

AuthService.Authentication authentication = new AuthService.Authentication();
authentication.Url = "<web_url>/_vti_bin/Authentication.asmx";
authentication.CookieContainer = new CookieContainer();
authentication.AllowAutoRedirect = true;
authentication.PreAuthenticate = true;
AuthenticationSoap authenticationSoap = null;
authenticationSoap = authentication.getAuthenticationSoap();
AuthServiceLoginResult loginResult = authenticationSoap.Login(username, password);

try adding the authentication soap call aswell! should work for on-premise

a similar answer answered by me here How to authenticate user in SharePoint online using javascript it also explains on soap calls.

9
  • I've tried with the code given in the link. But still I am getting the error "PasswordNotMatch".
    – Bishnu Das
    Commented Jul 9, 2014 at 10:40
  • are you 100% sure the account name and password is correct?
    – Ali Jafer
    Commented Jul 9, 2014 at 11:54
  • This is a domain account. And I use the credentials to login to the server. I've tried the username with both email id and domain\\username format
    – Bishnu Das
    Commented Jul 9, 2014 at 13:12
  • what version of sharepoint are you using? onpremise or online? if its online than its not supported.
    – Ali Jafer
    Commented Jul 9, 2014 at 13:38
  • It is SharePoint 2013 on-premise
    – Bishnu Das
    Commented Jul 10, 2014 at 6:13

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.