一个通用的MediaWiki OAuth握手助手。
mwoauth的Python项目详细描述
MediaWiki OAuth库
mwoauth是一个开放式许可(mit)库,旨在提供一种简单的方法,在安装了OAuth Extension的mediawiki安装中执行oauth握手。
与python 2.7和3.x兼容
使用pip安装:pip install mwoauth
用法
frommwoauthimportConsumerToken,Handshakerfromsix.movesimportinput# For compatibility between python 2 and 3# Consruct a "consumer" from the key/secret provided by MediaWikiimportconfigconsumer_token=ConsumerToken(config.consumer_key,config.consumer_secret)# Construct handshaker with wiki URI and consumerhandshaker=Handshaker("https://en.wikipedia.org/w/index.php",consumer_token)# Step 1: Initialize -- ask MediaWiki for a temporary key/secret for userredirect,request_token=handshaker.initiate()# Step 2: Authorize -- send user to MediaWiki to confirm authorizationprint("Point your browser to: %s"%redirect)#response_qs=input("Response query string: ")# Step 3: Complete -- obtain authorized key/secret for "resource owner"access_token=handshaker.complete(request_token,response_qs)print(str(access_token))# Step 4: Identify -- (optional) get identifying information about the useridentity=handshaker.identify(access_token)print("Identified as {username}.".format(**identity))