Пример #1
0
        internal string GetAuthenticationCookie(Uri url, bool refresh, bool alwaysThrowOnFailure)
        {
            if (url == null)
            {
                throw ClientUtility.CreateArgumentNullException("url");
            }
            if (!url.IsAbsoluteUri)
            {
                throw ClientUtility.CreateArgumentException("url");
            }
            Uri    uri  = new Uri(url, "/");
            string text = null;

            SharePointOnlineCredentials.CookieCacheEntry cookieCacheEntry = (SharePointOnlineCredentials.CookieCacheEntry) this.m_cachedCookies[uri];
            if (!refresh && cookieCacheEntry != null && cookieCacheEntry.IsValid)
            {
                ClientULS.SendTraceTag(3454916u, ClientTraceCategory.Authentication, ClientTraceLevel.Verbose, "Get cookie from cache for URL {0}", new object[]
                {
                    uri
                });
                return(cookieCacheEntry.Cookie);
            }
            if (refresh)
            {
                ISharePointOnlineAuthenticationProvider sharePointOnlineAuthenticationProvider = SharePointOnlineAuthenticationProviderHelper.CreateDefaultProvider();
                text = sharePointOnlineAuthenticationProvider.GetAuthenticationCookie(uri, this.m_userName, this.m_password, alwaysThrowOnFailure, this.ExecutingWebRequest);
                if (!string.IsNullOrEmpty(text))
                {
                    ClientULS.SendTraceTag(3454917u, ClientTraceCategory.Authentication, ClientTraceLevel.Medium, "Put cookie in cache for URL {0}", new object[]
                    {
                        uri
                    });
                    lock (this.m_lock)
                    {
                        this.m_cachedCookies[uri] = new SharePointOnlineCredentials.CookieCacheEntry
                        {
                            Cookie  = text,
                            Expires = DateTime.UtcNow.AddHours(1.0)
                        };
                    }
                }
            }
            return(text);
        }
        protected internal void UpdateClientObjectPropertyType(string propertyName, object propertyValue, JsonReader reader)
        {
            if (string.IsNullOrEmpty(propertyName))
            {
                throw ClientUtility.CreateArgumentNullException("propertyName");
            }
            if (propertyValue == null)
            {
                throw ClientUtility.CreateArgumentNullException("propertyValue");
            }
            if (reader == null)
            {
                throw ClientUtility.CreateArgumentNullException("reader");
            }
            ClientObject clientObject = propertyValue as ClientObject;

            if (clientObject == null)
            {
                throw ClientUtility.CreateArgumentException("propertyValue");
            }
            if (!this.ObjectData.ClientObjectProperties.ContainsKey(propertyName))
            {
                throw ClientUtility.CreateArgumentException("propertyName");
            }
            string scriptType;

            if (reader.PeekTokenType() == JsonTokenType.ObjectStart && reader.PeekObjectType(out scriptType))
            {
                Type typeFromScriptType = ScriptTypeMap.GetTypeFromScriptType(scriptType);
                //Edited for .NET Core
                //if (typeFromScriptType != null && typeFromScriptType != propertyValue.GetType() && propertyValue.GetType().IsAssignableFrom(typeFromScriptType))
                if (typeFromScriptType != null && typeFromScriptType != propertyValue.GetType())
                {
                    ClientObject clientObject2 = ScriptTypeMap.CreateObjectFromScriptType(scriptType, this.Context) as ClientObject;
                    if (clientObject2 != null)
                    {
                        clientObject.SetTypedObject(clientObject2);
                        this.ObjectData.ClientObjectProperties[propertyName] = clientObject2;
                    }
                }
            }
        }
Пример #3
0
        public SharePointOnlineCredentials(string username, SecureString password)
        {
            if (string.IsNullOrEmpty(username))
            {
                throw ClientUtility.CreateArgumentNullException("username");
            }
            int num = username.IndexOf('@');

            if (num < 0 || num == username.Length - 1)
            {
                throw ClientUtility.CreateArgumentException("username");
            }
            if (password == null)
            {
                throw ClientUtility.CreateArgumentNullException("password");
            }
            SharePointOnlineAuthenticationModule.EnsureRegistered();
            this.m_userName = username;
            this.m_password = password;
        }