3.4.15

Create Site SharePoint Rest C# CSOM


 private static string GetFormDigest(string token, string hdnHostWeb)
        {
            /* Retrieve a form digest, which is required for creating a new list item */

            string endpoint = hdnHostWeb + "/_api/contextinfo";
            HttpWebRequest digestRequest = (HttpWebRequest)HttpWebRequest.Create(endpoint);
            digestRequest.Headers.Add("Authorization", "Bearer " + token);
            digestRequest.Method = "POST";
            digestRequest.ContentLength = 0;

            HttpWebResponse digestResponse = (HttpWebResponse)digestRequest.GetResponse();
            XDocument responseDoc = XDocument.Load(digestResponse.GetResponseStream());

            XNamespace d = "http://schemas.microsoft.com/ado/2007/08/dataservices";
            string formDigest = responseDoc.Descendants(d + "FormDigestValue").First().Value;

            return formDigest;
        }

        public static Web CreateSite(string token, ClientContext cc, Web currentWeb, string template, int langue, bool heritage, string description, string titre, string url)
        {
            Web web = null;
            try
            {
                #region test
                string itemXML = "{'parameters': {'__metadata':  {'type': 'SP.WebInfoCreationInformation' },'Url': '" + url + "','Title': '" + titre + "','Description': '" + description + "','Language':" + langue + ",'WebTemplate':'" + template + "','UseUniquePermissions':'" + !heritage + "'}}";


                HttpWebRequest restRequest = (HttpWebRequest)HttpWebRequest.Create(currentWeb.Url + "/_api/web/webinfos/add");
                restRequest.Headers.Add("Authorization", "Bearer " + token);
                restRequest.Credentials = CredentialCache.DefaultCredentials;
                restRequest.Method = "POST";
                restRequest.Headers["X-RequestDigest"] = GetFormDigest(token, currentWeb.Url);
                restRequest.Accept = "application/json;odata=verbose";
                restRequest.ContentType = "application/json;odata=verbose";
                restRequest.ContentLength = itemXML.Length;
                StreamWriter sw = new StreamWriter(restRequest.GetRequestStream());
                sw.Write(itemXML);
                sw.Flush();

                //Get response
                HttpWebResponse restResponse = (HttpWebResponse)restRequest.GetResponse();
                StreamReader restStream = new StreamReader(restResponse.GetResponseStream());

                #endregion

                cc.Load(cc.Web.Webs);
                cc.ExecuteQuery();

                foreach (Web wb in cc.Web.Webs)
                {
                    if (wb.Title == titre || wb.Url == url)
                    {
                        web = wb;
                    }
                }
.....

2.4.15

Javascript MemberOf Group AD, query LDAP ( activeX enabled /!\ and only in IE /!\)


var ldapSearchJs = ldapSearchJs || {};

ldapSearchJs.getUserName = function () {
    var wshNetwork = new ActiveXObject("WScript.Network");
    var userName = wshNetwork.UserName;
    return userName;
}

ldapSearchJs.isMemberOf = function (userName, group) {
    objConnection = new ActiveXObject("ADODB.Connection");
    objConnection.Provider = "ADsDSOObject";
    objConnection.Open("ADs Provider");
    objCommand = new ActiveXObject("ADODB.Command");
    objCommand.ActiveConnection = objConnection;

    objCommand.CommandText = "SELECT distinguishedName, memberOf, primaryGroupID, objectSID FROM 'LDAP://DC=vca-share,DC=local' "
    + " WHERE   sAMAccountName='" + userName + "' and memberof='CN=" + group + ",CN=Users,DC=vca-share,DC=local'"; //(memberOf=cn=adminsp,ou=users,dc=vca-share,DC=local))";

    objRecordSet = objCommand.Execute();

    var userMail, lastName, firstName;
    if (objRecordSet.RecordCount > 0) {
        isMemberOf = 'Yes, ' + userName + ' is memeber of ' + group;
    }
    else {
        isMemberOf = 'No';
    }
    objConnection.Close;

    return isMemberOf;
}


$(document).ready(function () {

    alert(
        ldapSearchJs.isMemberOf(ldapSearchJs.getUserName(), 'adminsp')
        );
});









































17.2.15

SharePoint App Dev Note


##Grab the cert and create the object##
$publicCertPath = "C:\vca-share.cer"
$certificate = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($publicCertPath)
##Certificate treated as root authority##
New-SPTrustedRootAuthority -Name "HighTrustAppCert" -Certificate $certificate
##Setup token issuer which is the certificate itself##
$realm = Get-SPAuthenticationRealm
$specificIssuerId = [System.Guid]::NewGuid().ToString()
$specificIssuerId
$fullIssuerIdentifier = $specificIssuerId + '@' + $realm
New-SPTrustedSecurityTokenIssuer -Name "HighTrustAppCert" -Certificate $certificate -RegisteredIssuerName $fullIssuerIdentifier -IsTrustBroker
iisreset
$serviceConfig = Get-SPSecurityTokenServiceConfig
$serviceConfig.AllowOAuthOverHttp = $true
$serviceConfig.Update()
$specificIssuerId


http://{sharepoint}/_layouts/15/AppRegNew.aspx


New-SPSubscriptionSettingsServiceApplication -ApplicationPool "SharePoint Web Services Default" -Name "Subscription Settings Service Application" -DatabaseName "SubscriptionSettingsDB" | New-SPSubscriptionSettingsServiceApplicationProxy

New-SPSubscriptionSettingsServiceApplication -ApplicationPool "SharePoint Web Services Default" -Name "Subscription Settings Service Application" -DatabaseName "SubscriptionSettingsDB" | New-SPSubscriptionSettingsServiceApplicationProxy

New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa -Name "DisableLoopbackCheck" -Value "1" -PropertyType dword

 
$serviceConfig = Get-SPSecurityTokenServiceConfig$serviceConfig AllowOAuthOverHttp = $true $serviceConfig.Update()

http://sharepoint.stackexchange.com/questions/79284/getting-401-403-in-high-trust-app-for-sharepoint-2013

system.net tag:
<settings>
<servicePointManager
 checkCertificateName=”false”
 checkCertificateRevocationList=”false”/>
</settings>