A
A
alex5e2015-02-07 18:29:53
Java
alex5e, 2015-02-07 18:29:53

How to emulate authorization on someone else's site through VKontakte?

Good afternoon. I ran into a problem when emulating authorization on the site through the VKontakte widget. I use java and htmlUnit. The problem is this. When you enter the site, you click on the button to enter through VK, a pop-up window appears 1fc9f9dbd0014224b34741cbc5ea4b3d.PNG
In the browser, after clicking on the "Allow" button, the window closes and the page (on which the login was performed) is updated. In htmlUnit after clicking on the "Allow" button. the application is installed, but the login on the site does not occur. (After refreshing the page, the user also remains unlogged).

String applicationName = "Mozilla";
String applicationVersion = "5.0";
String userAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0";
int browserVersionNumeric = 35;
BrowserVersion Mozilla35 = new BrowserVersion(applicationName, applicationVersion, userAgent, browserVersionNumeric);
                    
WebClient likesFm = new WebClient(Mozilla35);
likesFm.addRequestHeader("Accept-Language", "ru");
likesFm.setJavaScriptTimeout(10*1000);
likesFm.getOptions().setCssEnabled(false);
likesFm.getOptions().setRedirectEnabled(true);
likesFm.getOptions().setThrowExceptionOnScriptError(false);
likesFm.getOptions().setGeolocationEnabled(true);
likesFm.getOptions().setUseInsecureSSL(true);
likesFm.setAjaxController(new NicelyResynchronizingAjaxController());
likesFm.getCookieManager().setCookiesEnabled(true);
likesFm.getOptions().setJavaScriptEnabled(true);
likesFm.getOptions().setThrowExceptionOnFailingStatusCode(false);
likesFm.getOptions().setTimeout(60*1000);
likesFm.getOptions().setPopupBlockerEnabled(false);
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF); 
java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.OFF); 
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
HtmlPage vkPage = likesFm.getPage(new WebRequest(new URL("https://vk.com/"), HttpMethod.POST));
final HtmlForm vkForm = vkPage.getFormByName("login");
final HtmlSubmitInput vkButton = (HtmlSubmitInput)vkForm.getFirstByXPath("//*[@id=\'quick_login_form\']/input[8]");
final HtmlTextInput vkEmail = vkForm.getInputByName("email");
final HtmlPasswordInput vkPass = vkForm.getInputByName("pass");
vkEmail.setValueAttribute(this.login);
vkPass.setValueAttribute(this.pass);
/* Залогинились ВКонтакте */
final HtmlPage pageLoginVk = vkButton.click();
 /* Логинимся на сайте */
final HtmlPage likes = likesFm.getPage("https://likes.fm/");   
System.out.println(likesFm.getCurrentWindow().getEnclosedPage());
final HtmlButton oauth = likes.getFirstByXPath("/html/body/div[3]/div[1]/div[1]/button");
//ВКонтакте | Разрешение доступа
final HtmlPage oauthres = oauth.click();
System.out.println(likesFm.getCurrentWindow().getEnclosedPage());
final HtmlButton oauth2;
final HtmlPage oauthres2;
if(oauthres.getTitleText().contains("ВКонтакте")) {  
        oauth2 = oauthres.getFirstByXPath("//*[@id=\"install_allow\"]");
        oauthres2 = oauth2.click();
} else {
        String parameterss = likesFm.getCookieManager().getCookies().toString();
        System.out.println(parameterss);
        likesFm.waitForBackgroundJavaScript(1000);
        likesFm.waitForBackgroundJavaScriptStartingBefore(1000);
}
System.out.println(oauthres.getBody().asText());
final HtmlPage likes1 = likesFm.getPage("https://likes.fm/");
System.out.println(likes1.getBody().asText());

Maybe someone did something similar? Tell..

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel, 2017-09-22
@mrusklon

because the whole /public_html/bitrix/* folder is ignored

M
Max Medar, 2017-09-22
@MedVedar

https://git-scm.com/docs/gitignore
For quick generation:
https://www.gitignore.io/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question