void HandlePreAuthentication(HttpURLConnection httpConnection) { AuthenticationData data = PreAuthenticationData; if (!PreAuthenticate || data == null) { return; } ICredentials creds = data.UseProxyAuthentication ? Proxy?.Credentials : Credentials; if (creds == null) { return; } IAndroidAuthenticationModule auth = data.Scheme == AuthenticationScheme.Unsupported ? data.AuthModule : authModules.Find(m => m?.Scheme == data.Scheme); if (auth == null) { return; } Authorization authorization = auth.Authenticate(data.Challenge, httpConnection, creds); if (authorization == null) { return; } httpConnection.SetRequestProperty(data.UseProxyAuthentication ? "Proxy-Authorization" : "Authorization", authorization.Message); }
void HandlePreAuthentication(HttpURLConnection httpConnection) { AuthenticationData data = PreAuthenticationData; if (!PreAuthenticate || data == null) { return; } ICredentials creds = data.UseProxyAuthentication ? Proxy?.Credentials : Credentials; if (creds == null) { if (Logger.LogNet) { Logger.Log(LogLevel.Info, LOG_APP, $"Authentication using scheme {data.Scheme} requested but no credentials found. No authentication will be performed"); } return; } IAndroidAuthenticationModule auth = data.Scheme == AuthenticationScheme.Unsupported ? data.AuthModule : authModules.Find(m => m?.Scheme == data.Scheme); if (auth == null) { if (Logger.LogNet) { Logger.Log(LogLevel.Info, LOG_APP, $"Authentication module for scheme '{data.Scheme}' not found. No authentication will be performed"); } return; } Authorization authorization = auth.Authenticate(data.Challenge, httpConnection, creds); if (authorization == null) { if (Logger.LogNet) { Logger.Log(LogLevel.Info, LOG_APP, $"Authorization module {auth.GetType ()} for scheme {data.Scheme} returned no authorization"); } return; } if (Logger.LogNet) { var header = data.UseProxyAuthentication ? "Proxy-Authorization" : "Authorization"; Logger.Log(LogLevel.Info, LOG_APP, $"Authentication header '{header}' will be set to '{authorization.Message}'"); } httpConnection.SetRequestProperty(data.UseProxyAuthentication ? "Proxy-Authorization" : "Authorization", authorization.Message); }