When I query my web service to find a user, if that user is not part of a SharePoint group for the site, the ID is -1.
However, the user CAN get to the site, via a group permission. So my web service call cannot add the user to a "people" box within a list, even though SharePoint itself CAN add it.
My Web service call is as follows:
String searchText = "[My User's Login Name, Spelled Exactly as it appears in SharePoint.]";
String maxresults = "100";
String pType = "All";
String body = "<?xml version=\"1.0\"?>"
+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+ " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
+ " xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+ "<soap:Body>"
+ " <SearchPrincipals "
+ " xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">"
+ " <searchText>" + searchText + "</searchText>"
+ " <maxResults>" + maxResults + "</maxResults>"
+ " <principalType>" + pType + "</principalType>"
+ " </SearchPrincipals>"
+ " </soap:Body>"
+ "</soap:Envelope>";
I get the following response from the web service call:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<SearchPrincipalsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
<SearchPrincipalsResult>
<PrincipalInfo>
<AccountName>[User's Account Name]</AccountName>
<UserInfoID>-1</UserInfoID> <------------ NOTE THE -1 HERE -----------------
<DisplayName>[User's full name, exactly as I sent it in]</DisplayName>
<Email>...</Email>
<Department>...</Department>
<Title>...</Title>
<IsResolved>true</IsResolved>
<PrincipalType>User</PrincipalType>
</PrincipalInfo>
</SearchPrincipalsResult>
</SearchPrincipalsResponse>
</soap:Body>
</soap:Envelope>
If I use this information to add a user to a "people" box, via the web service, The entry becomes "-1;#My User Name", which of course it cannot find, so the List.asmx webservice returns an error of 0x81020054 : The user does not exist or is not unique.
When I add the user to a group within the site directly, their ID resolves out just fine and everything goes through as normal. I remove them from the group and it returns to -1 again.
Any thoughts and/or suggestions for always returning a valid ID?
I can see you are using SearchPrincipals method. Instead try using ResolvePrincipals method.
Documentation here: http://msdn.microsoft.com/en-us/library/people.people.resolveprincipals(v=office.12).aspx
That method has a bool parameter where you can specify that if the user does not belong to the site, then it should be added, this way you will always make sure that you are always getting the ID even if the user does not belong to the site.
PeopleWebService.People pe = new PeopleWebService.People(); //People.asmx web service
string[] users = new string[] { "youruser" };
PeopleWebService.PrincipalInfo[] pInfo = pe.ResolvePrincipals(users, PeopleWebService.SPPrincipalType.User, true); //third param is true
string userID = pInfo[0].UserInfoID.ToString();
Related
I have been working on a brute forcer, for practice and I'm almost done its just I need to clarify whether or not, I have to send the username and password in plain text or do I just encode it using base64, before I send it to the Web Server.
Here is the message I'm sending right now, to the Web Server.
string m;
m = "POST " + URI + " " + "HTTP/1.1" + \n" +
"Authorization: " + "Basic " + user + ":" + pass;
Yes, you have to encode it.
From Wiki: https://en.wikipedia.org/wiki/Basic_access_authentication
The Authorization field is constructed as follows:
Username and password are combined into a string "username:password".
The resulting string is then encoded using the RFC2045-MIME variant of
Base64, except not limited to 76 char/line.
The authorization method and a space i.e. "Basic " is then put before the encoded string.
For
example, if the user agent uses 'Aladdin' as the username and 'open
sesame' as the password then the field is formed as follows:
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
More on RFC2045: https://en.wikipedia.org/wiki/Base64
I followed the advice provided here and it worked like a charm. Right now, I'm connecting to the server and calling a method named GetFunctionalityTest. The only input to it is a string, which can be seen in the GetFunctionalityTest.m file. So far so good.
Then I attempted to call the real service named GetSections whose signature according to the file GetSections.m is as follows.
function GetSectionsResult = GetSections(obj,auth)
% GetSections(obj,auth)
% Input: auth = (Authorize)
% Output: GetSectionsResult = (ArrayOfString)
values = { auth, };
names = { 'auth', };
types = { '{WSPro.HostingWebservice}Authorize', };
soapMessage = createSoapMessage( ...
'WSPro.HostingWebservice', ...
'GetSections', values,names,types,'document');
response = callSoapService( obj.endpoint, ...
'WSPro.HostingWebservice/GetSections', soapMessage);
GetSectionsResult = parseSoapResponse(response);
The definition provided by the server is as follows.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi=...>
<soap:Body>
<GetSections xmlns="WSPro.HostingWebservice">
<auth>
<uid>string</uid>
<pw>string</pw>
</auth>
</GetSections>
</soap:Body>
</soap:Envelope>
My problem is that I can't specify the authorization syntax-wise. As far I understand, it's supposed to consist of two strings somehow but I haven't get it to work. I've tried to compound those as follows.
myAuthorization = ['user', 'pass'];
myAuthorization = {'user', 'pass'};
myAuthorization = ['user' 'pass'];
myAuthorization = {'user' 'pass'};
Nothing helped. I just got a bunch of errors.
Error using callSoapService (line 147)
Unspecified Fault: SOAP Fault: Server was unable to process request.
---> The parameterized query
'(#uid nvarchar(99)) SELECT PassW FROM UserData WHERE UserId = #' expects the parameter '#uid', which was not supplied.
I've browsed all the files automatically created for me and there's no definition of Authorize not ArrayOfString. I'm guessing it's something that the server defines, since I get no hits on those in MatLab documentation.
How can I specify the credentials for authorization?
Where can I look up how MatLab maps Authorization?
As noted above:
The SOAP Authentication happens through SOAP Header and not SOAP Body.This link might give you an idea of how SOAP XML should look in case of authentication :
Web service soap header authentication
I'm implementing the X-FACEBOOK-PLATFORM XMPP authentication in Objective C (but using mostly C++ code) and I am getting always a failure:
<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>
I have the the app registered and the Id and Secret are as follows:
FacebookId #"136973476410894"
FacebookSecret #"f6e269fe158b4a04d00ce8b311453ccd"
I retrieve the session Token with FBConnect asking for the privileges:
#"publish_stream" ,#"xmpp_login" , #"offline_access"
The Session token is called token in the code (see below)
And then the program asks for the authentication mechanism:
<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="X-FACEBOOK-PLATFORM"/>
Receiving the challenge: <challenge xmlns="urn:ietf:params:xml:ns:xmpp-sasl">dmVyc2lvbj0xJm1ldGhvZD1hdXRoLnhtcHBfbG9naW4mbm9uY2U9OTAzMTM5MjY2ODk3N0Q0ODMyNDQ2MDY1REMzMTE5RTc=</challenge>
Then the Facebook Auth body extracted from the challenge: version=1&method=auth.xmpp_login&nonce=9031392668977D4832446065DC3119E7.
key: version, value: 1.
key: method, value: auth.xmpp_login.
key: nonce, value: 9031392668977D4832446065DC3119E7.
token: "BAAB8k59ntg4BANNuTHAkjTZBk3pW8pZBD7jWIpZBt8cf65oAT4eDm9euloGCX9NzfF9HwKQxUdEQ15YfeFtkdZAHVpkjL0j4CF0lZCQeuNTBXrvkbtUXC"
APIkey: "136973476410894"
APISecret: "f6e269fe158b4a04d00ce8b311453ccd"
Using the code from below a response is built:
token = Session token from FB connect: (BAAB8k59ntg4BANNuTHAkjTZBk3pW8pZBD7jWIpZBt8cf65oAT4eDm9euloGCX9NzfF9HwKQxUdEQ15YfeFtkdZAHVpkjL0j4CF0lZCQeuNTBXrvkbtUXC)
APIkey = FacebookId (136973476410894);
APISecret = FacebookSecret (f6e269fe158b4a04d00ce8b311453ccd);
string call_id=[[NSString stringWithFormat:#"%0.0f", [[NSDate date] timeIntervalSince1970]] UTF8String];
string signature1 = "api_key=" + APIkey
+ "call_id=" + call_id
+ "method=auth.xmpp_login"
+ "nonce=" + nonce
+ "session_key=" + token
+ "v=1.0"
+ APISecret;
string md = MD5(signature1);
//std::transform(md.begin(), md.end(),md.begin(), ::tolower);
string response2 = "method=auth.xmpp_login&api_key=" + APIkey + "&session_key=" +token + "&call_id=" + call_id + "&sig=" + md + "&v=1.0&" + "nonce=" + nonce;
printf("++base64EncodedResponse response2: %s.\n", response2.c_str());
string response2Base64 = Base64::Encode(response2);
Built response: method=auth.xmpp_login&api_key=136973476410894&session_key=BAAB8k59ntg4BANNuTHAkjTZBk3pW8pZBD7jWIpZBt8cf65oAT4eDm9euloGCX9NzfF9HwKQxUdEQ15YfeFtkdZAHVpkjL0j4CF0lZCQeuNTBXrvkbtUXC&call_id=1321457495&sig=5f376192b2dd1f5f928f651a996ce757&v=1.0&nonce=9031392668977D4832446065DC3119E7
Stanza sent(response): <response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">bWV0aG9kPWF1dGgueG1wcF9sb2dpbiZhcGlfa2V5PTEzNjk3MzQ3NjQxMDg5NCZzZXNzaW9uX2tleT1CQUFCOGs1OW50ZzRCQU5OdVRIQWtqVFpCazNwVzhwWkJEN2pXSXBaQnQ4Y2Y2NW9BVDRlRG05ZXVsb0dDWDlOemZGOUh3S1F4VWRFUTE1WWZlRnRrZFpBSFZwa2pMMGo0Q0YwbFpDUWV1TlRCWHJ2a2J0VVhDJmNhbGxfaWQ9MTMyMTQ1NzQ5NSZzaWc9NWYzNzYxOTJiMmRkMWY1ZjkyOGY2NTFhOTk2Y2U3NTcmdj0xLjAmbm9uY2U9OTAzMTM5MjY2ODk3N0Q0ODMyNDQ2MDY1REMzMTE5RTc=</response>
And the server returns:
<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized/></failure>
I don't know where the problem is, it looks right to me, but there is no way to authenticate. Does anybody knows if there is any way to debug with the server the reason for the failure? May it be that the App is not yet in the App Store?
If someone can help it would be very welcome!
Since no one responded and someone else can get tricked by this same error due to the fact that this code appears on some examples about Facebook Authentication- I will post the response myself.
Everything is almost ok, it only requires the tag session_key to be changed for access_token in the signature1 string and in the response2 string.
I'm using HTTPWebRequest/HTTPWebResponse to interact with the site (www.lockerz.com). So, I authenticate on the site:
HttpWebRequest webRequest = (HttpWebRequest) HttpWebRequest.Create("http://www.lockerz.com/auth/login");
byte[] bytes = Encoding.ASCII.GetBytes("handle=" + textBoxEmail.Text + "&password=" + textBoxPassword.Text);
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "POST";
webRequest.ContentLength = bytes.Length;
Stream os = webRequest.GetRequestStream();
os.Write(bytes, 0, bytes.Length);
Then I get the response:
HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
I'm watching the requests\responses using Charles and it says that in the response there must be cookies, but when I try to make a list of the cookies I get it says that there are no cookies!
foreach(Cookie c in webResponse.Cookies) {
writeToLog("Cookie Name: " + c.Name + " Value: " + c.Value);
cc.Add(c);
}
I've tried adding a CookieContainer but it doesn't work anyway.
This may apply here, I have had this problem with sessions, so I will assume the same for cookies.
You are making a call to: http://www.lockerz.com/auth/login. But if a person goes to a page without the "www." part of the url, then their cookies won't survive being sent to the "www." site, because they are different sites (as far as the cookies are concerned).
I would just make the request to "/auth/login", that way, it won't matter what the user has as the url in their browser.
Hope this works.
On a remote client, I'm trying to create a new list in a sharepoint site. Right now, I'm building a CAML string and sending it via http post to my sharepoint site. I've used this method to update list items and create dws folders, but I can't seem to get AddList to work. I get an error "Remove server returned error:NotFound."
here is my CAML:
string soapEnv =
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance" +
"xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"" +
" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
"<soap:Body>" +
"<AddList xmlns=\"http://schemas.microsoft.com/sharepoint/soap\">" +
"<listName>" + listName + "</listName>" +
"<description>" + "A Test list" + "</description>" +
"<templateID>100</templateID>" +
"</AddList>" +
"</soap:Body>" +
"</soap:Envelope>";
return soapEnv;
I send this in an http Post with these settings:
uri = "[my sharepoint site]/_vti_bin/lists.asmx";
WebClient client = new WebClient();
client.Headers["SOAPAction"] = "http://schemas.microsoft.com/sharepoint/soap/";
client.Headers["content-type"] = "text/xml; charset=utf-8";
client.Encoding = Encoding.UTF8;
client.UploadStringCompleted += UploadStringCompleted;
try
{
client.UploadStringAsync(new Uri(uri, UriKind.Absolute), "POST", CAML);
}
catch (Exception ex)
{
MessageBox.Show("Error in upload string async: " + ex.Message);
}
Any ideas? I'm pretty certain it's not an authentication issue since I've used the exact same method in this same program to do the previously mentioned functions. The sharepoint site I'm adding the list to is a test site in which I have full read/write capabilities.
D'oh!
In this part of the soap:Envelope tag: "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance"
I had XMLSchema-instance" instead of XMLSchema\"". I needed that extra parentheses to finish that string...