Пример #1
0
 public string GetAuthenticationCookie(Uri url, string username, SecureString password, bool alwaysThrowOnFailure, EventHandler <SharePointOnlineCredentialsWebRequestEventArgs> executingWebRequest)
 {
     if (url == null)
     {
         throw new ArgumentNullException("url");
     }
     if (string.IsNullOrEmpty(username))
     {
         throw new ArgumentNullException("username");
     }
     if (password == null)
     {
         throw new ArgumentNullException("password");
     }
     SharePointOnlineAuthenticationProvider.IdcrlHeader idcrlHeader = this.GetIdcrlHeader(url, alwaysThrowOnFailure, executingWebRequest);
     if (idcrlHeader == null)
     {
         ClientULS.SendTraceTag(3991707u, ClientTraceCategory.Authentication, ClientTraceLevel.Medium, "Cannot get IDCRL header for {0}", new object[]
         {
             url
         });
         if (alwaysThrowOnFailure)
         {
             throw new ClientRequestException(Resources.GetString("CannotContactSite", new object[]
             {
                 url
             }));
         }
         return(null);
     }
     else
     {
         IdcrlEnvironment env;
         if (string.Compare(SharePointOnlineAuthenticationProvider.IdcrlServiceEnvironment, "INT-MSO", StringComparison.OrdinalIgnoreCase) == 0)
         {
             env = IdcrlEnvironment.Int;
         }
         else if (string.Equals(SharePointOnlineAuthenticationProvider.IdcrlServiceEnvironment, "PPE-MSO", StringComparison.OrdinalIgnoreCase))
         {
             env = IdcrlEnvironment.Ppe;
         }
         else
         {
             env = IdcrlEnvironment.Production;
         }
         IdcrlAuth idcrlAuth = new IdcrlAuth(env, executingWebRequest);
         //Edited for .NET Core - Changed from SecureString to string
         string password2    = SharePointOnlineAuthenticationProvider.FromSecureString(password);
         string serviceToken = idcrlAuth.GetServiceToken(username, password2, idcrlHeader.ServiceTarget, idcrlHeader.ServicePolicy);
         if (!string.IsNullOrEmpty(serviceToken))
         {
             return(this.GetCookie(url, idcrlHeader.Endpoint, serviceToken, alwaysThrowOnFailure, executingWebRequest));
         }
         ClientULS.SendTraceTag(3991708u, ClientTraceCategory.Authentication, ClientTraceLevel.Medium, "Cannot get IDCRL ticket for username {0}", new object[]
         {
             username
         });
         if (alwaysThrowOnFailure)
         {
             throw new IdcrlException(Resources.GetString("PPCRL_REQUEST_E_UNKNOWN", new object[]
             {
                 -2147186615
             }));
         }
         return(null);
     }
 }
Пример #2
0
 private SharePointOnlineAuthenticationProvider.IdcrlHeader ParseIdcrlHeader(string headerValue, Uri url, HttpStatusCode statusCode, string allResponseHeaders, bool alwaysThrowOnFailure)
 {
     if (!string.IsNullOrWhiteSpace(headerValue))
     {
         SharePointOnlineAuthenticationProvider.IdcrlHeader idcrlHeader = new SharePointOnlineAuthenticationProvider.IdcrlHeader();
         string[] array = headerValue.Split(new char[]
         {
             ','
         });
         for (int i = 0; i < array.Length; i++)
         {
             string   text   = array[i];
             string   text2  = text.Trim();
             string[] array2 = text2.Split(new char[]
             {
                 '='
             });
             if (array2.Length == 2)
             {
                 array2[0] = array2[0].Trim().ToUpperInvariant();
                 array2[1] = array2[1].Trim(new char[]
                 {
                     ' ',
                     '"'
                 });
                 string a;
                 if ((a = array2[0]) != null)
                 {
                     if (!(a == "IDCRL TYPE"))
                     {
                         if (!(a == "ENDPOINT"))
                         {
                             if (!(a == "ROOTDOMAIN"))
                             {
                                 if (a == "POLICY")
                                 {
                                     idcrlHeader.ServicePolicy = array2[1];
                                 }
                             }
                             else
                             {
                                 idcrlHeader.ServiceTarget = array2[1];
                             }
                         }
                         else
                         {
                             idcrlHeader.Endpoint = array2[1];
                         }
                     }
                     else
                     {
                         idcrlHeader.IdcrlType = array2[1];
                     }
                 }
             }
         }
         if (idcrlHeader.IdcrlType != "BPOSIDCRL" || string.IsNullOrEmpty(idcrlHeader.ServicePolicy) || string.IsNullOrEmpty(idcrlHeader.ServiceTarget) || string.IsNullOrEmpty(idcrlHeader.Endpoint))
         {
             ClientULS.SendTraceTag(3991714u, ClientTraceCategory.Authentication, ClientTraceLevel.Medium, "Cannot extract required information from IDCRL header. Header={0}, IdcrlType={1}, ServicePolicy={2}, ServiceTarget={3}, Endpoint={4}", new object[]
             {
                 headerValue,
                 idcrlHeader.IdcrlType,
                 idcrlHeader.ServicePolicy,
                 idcrlHeader.ServiceTarget,
                 idcrlHeader.Endpoint
             });
             if (alwaysThrowOnFailure)
             {
                 throw new ClientRequestException(Resources.GetString("InvalidIdcrlHeader", new object[]
                 {
                     url.OriginalString,
                     headerValue,
                     statusCode,
                     allResponseHeaders
                 }));
             }
             idcrlHeader = null;
         }
         return(idcrlHeader);
     }
     ClientULS.SendTraceTag(3991713u, ClientTraceCategory.Authentication, ClientTraceLevel.Medium, "IDCRL header value is empty", new object[0]);
     if (alwaysThrowOnFailure)
     {
         throw new NotSupportedException(Resources.GetString("SharePointClientCredentialsNotSupported", new object[]
         {
             url.OriginalString,
             statusCode,
             allResponseHeaders
         }));
     }
     return(null);
 }