public IdcrlAuth(IdcrlEnvironment env, EventHandler <SharePointOnlineCredentialsWebRequestEventArgs> executingWebRequest)
 {
     this.m_env = env;
     ClientULS.SendTraceTag(3454918u, ClientTraceCategory.Authentication, ClientTraceLevel.Verbose, "IDCRL Environment {0}", new object[]
     {
         env
     });
     if (this.m_env == IdcrlEnvironment.Production)
     {
         this.m_userRealmServiceUrl     = "https://login.microsoftonline.com/GetUserRealm.srf";
         this.m_securityTokenServiceUrl = "https://login.microsoftonline.com/rst2.srf";
         this.m_federationTokenIssuer   = "urn:federation:MicrosoftOnline";
     }
     else if (this.m_env == IdcrlEnvironment.Ppe)
     {
         this.m_userRealmServiceUrl     = "https://login.windows-ppe.net/GetUserRealm.srf";
         this.m_securityTokenServiceUrl = "https://login.windows-ppe.net/rst2.srf";
         this.m_federationTokenIssuer   = "urn:federation:MicrosoftOnline";
     }
     else
     {
         this.m_userRealmServiceUrl     = "https://login.microsoftonline-int.com/GetUserRealm.srf";
         this.m_securityTokenServiceUrl = "https://login.microsoftonline-int.com/rst2.srf";
         this.m_federationTokenIssuer   = "urn:federation:MicrosoftOnline-int";
     }
     this.m_executingWebRequest = executingWebRequest;
 }
Esempio n. 2
0
 public IdcrlAuth(IdcrlEnvironment env, EventHandler <WebRequestEventArgs> executingWebRequest, ILogger logger)
 {
     this.m_env   = env;
     this._Logger = logger;
     this._Logger?.LogInformation("IDCRL Environment {0}", env);
     if (this.m_env == IdcrlEnvironment.Production)
     {
         this.m_userRealmServiceUrl     = "https://login.microsoftonline.com/GetUserRealm.srf";
         this.m_securityTokenServiceUrl = "https://login.microsoftonline.com/rst2.srf";
         this.m_federationTokenIssuer   = "urn:federation:MicrosoftOnline";
     }
     else if (this.m_env == IdcrlEnvironment.Ppe)
     {
         this.m_userRealmServiceUrl     = "https://login.windows-ppe.net/GetUserRealm.srf";
         this.m_securityTokenServiceUrl = "https://login.windows-ppe.net/rst2.srf";
         this.m_federationTokenIssuer   = "urn:federation:MicrosoftOnline";
     }
     else
     {
         this.m_userRealmServiceUrl     = "https://login.microsoftonline-int.com/GetUserRealm.srf";
         this.m_securityTokenServiceUrl = "https://login.microsoftonline-int.com/rst2.srf";
         this.m_federationTokenIssuer   = "urn:federation:MicrosoftOnline-int";
     }
     this.m_executingWebRequest = executingWebRequest;
 }
Esempio n. 3
0
        public async Task <string> GetAuthenticationCookieAsync(Uri url, string username, string password, bool alwaysThrowOnFailure, EventHandler <WebRequestEventArgs> executingWebRequest)
        {
            if (url == (Uri)null)
            {
                throw new ArgumentNullException("url");
            }
            if (string.IsNullOrEmpty(username))
            {
                throw new ArgumentNullException("username");
            }
            if (password == null)
            {
                throw new ArgumentNullException("password");
            }
            IdcrlHeader idcrlHeader = this.GetIdcrlHeader(url, alwaysThrowOnFailure, executingWebRequest);

            if (idcrlHeader == null)
            {
                this._Logger?.LogWarning("Cannot get IDCRL header for {0}", url);
                if (alwaysThrowOnFailure)
                {
                    throw new ClientRequestException($"CannotContactSite {url}");
                }
                return(null);
            }
#if UseRegistry
            IdcrlEnvironment env       = (IdcrlEnvironment)((string.Compare(IdcrlServiceEnvironment, "INT-MSO", StringComparison.OrdinalIgnoreCase) == 0) ? 1 : (string.Equals(IdcrlServiceEnvironment, "PPE-MSO", StringComparison.OrdinalIgnoreCase) ? 2 : 0));
            IdcrlAuth        idcrlAuth = new IdcrlAuth(env, executingWebRequest, this._Logger);
#else
            IdcrlAuth idcrlAuth = new IdcrlAuth(executingWebRequest, this._Logger);
#endif
            string serviceToken = await idcrlAuth.GetServiceTokenAsync(username, password, idcrlHeader.ServiceTarget, idcrlHeader.ServicePolicy);

            if (string.IsNullOrEmpty(serviceToken))
            {
                this._Logger?.LogWarning("Cannot get IDCRL ticket for username {0}", username);
                if (alwaysThrowOnFailure)
                {
                    throw new IdcrlException("PPCRL_REQUEST_E_UNKNOWN  -2147186615");
                }
                return(null);
            }
            return(this.GetCookie(url, idcrlHeader.Endpoint, serviceToken, alwaysThrowOnFailure, executingWebRequest));
        }