Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login with clientlogin #1

Open
CXuesong opened this issue Aug 19, 2016 · 8 comments
Open

Login with clientlogin #1

CXuesong opened this issue Aug 19, 2016 · 8 comments

Comments

@CXuesong
Copy link
Owner

This library aims to provide functionality for both bots and users, so it's important, especially in the future, to implement clientlogin action.

See https://www.mediawiki.org/wiki/API:Login#The_clientlogin_action .

@bjm3819
Copy link

bjm3819 commented Mar 3, 2017

yes having a clientlogin, kerberos, or even oAuth would help. For example: the private media wiki is configured by apache to use kerberos authentication.

@CXuesong
Copy link
Owner Author

CXuesong commented Mar 5, 2017

However, it seems that the parameters needed by clientlogin varies greatly from site to site. Some sites may need captcha code; other sites may need openAuth. It may take considerable effort to build a login interface covering every situation, which I lack for this year. Thus perhaps such login routine may need to be implemented by the library client, using Site.PostValuesAsync methods. After this, the client need to invoke Site.RefreshUserInfoAsync (Oh, I should have renamed it to RefreshAccountInfoAsync), and the login procedure will be done.

Though it may still be desirable to have some simple clientlogin patterns implemented out-of-the-box, like the ones that only need a user name and a password, which will eliminate MediaWiki's deprecation warning.

As for kerberos, I will add an option in WikiClient to decide whether to pass the credentials to the server. Unfortunately, there is a bug in HttpClient with kerberos, that it is impossible for a user to login with a different credential.

@bjm3819
Copy link

bjm3819 commented Mar 6, 2017 via email

@bjm3819
Copy link

bjm3819 commented Mar 6, 2017 via email

@bjm3819
Copy link

bjm3819 commented Mar 6, 2017 via email

@CXuesong
Copy link
Owner Author

CXuesong commented Mar 7, 2017

I have exposed some credential-related properties in WikiClient not long ago. However, it strikes me that I might as well give the client a chance to pass in their ownHttpClientHandler (or generally, HttpMessageHandler) in the ctor, so here is 2ab4683 .

You can set up your own HttpClientHandler; then configure its Credentials, UseDefaultCredentials, and PreAuthenticate, if necessary. Don't forget to set UseCookies and AutomaticDecompression. Fianlly, pass it to WikiClient like this

var client = new WikiClient(youHandler, true);

As for the question on SO, frankly I haven't done much research on HttpMessageHandler yesterday. Now I think it's weird that nobody even mentioned HttpClientHandler.Credentials property, and I believe this property is exactly what you are looking for. You need to implement the interface, and return a System.Net.NetworkCredential containing user name and password when needed. Anyway, the bottom line is that I don't want to use WebClient, because it doesn't support multi-threaded requests. You cannot perform two requests simultaneously on one WebClient instance.

I'm also considering extract a base class from WikiClient, but it should not affect the public members in WikiClient itself. After that, I will publish a pre-release on NuGet.

p.s.

On which version of .NET framework are you using? I'm just curious ;-)

Also, please note that this project is still in version 0.x, and the public interface may change in later versions.

@CXuesong
Copy link
Owner Author

CXuesong commented Mar 7, 2017

As for the token problem… Well, I haven't come across that before. Please open an issue and provide some more information on it, including your MediaWiki version, and the stack trace. Thank you!

@CXuesong
Copy link
Owner Author

CXuesong commented Mar 7, 2017

And clientlogin… Well, I think perhaps I will have to implement the whole procedure, because API documentation just told us to query for the available parameters

This module accepts additional parameters depending on the available authentication requests. Use action=query&meta=authmanagerinfo with amirequestsfor=login (or a previous response from this module, if applicable) to determine the requests available and the fields that they use.

I think this module is just intended for human, and the client library should just query for the available fields, and gives it directly back to the client application, which will in turn shows them to the human user.

Wish me good luck. Before that, you may either generate bot password for your bots, or continue using LoginAsync.

CXuesong pushed a commit that referenced this issue Aug 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants