File: README.rst

package info (click to toggle)
mwoauth 0.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 164 kB
  • sloc: python: 390; makefile: 4
file content (41 lines) | stat: -rw-r--r-- 1,464 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
MediaWiki OAuth Library
=======================

``mwoauth`` is an open licensed (MIT) library designed to provide a simple means to performing an OAuth handshake with a MediaWiki installation with the `OAuth Extension <https://www.mediawiki.org/wiki/Extension:OAuth>`_ installed.  

**Compatible with python 3.x**

**Install with pip:** ``pip install mwoauth``

**Documentation:** http://pythonhosted.org/mwoauth

Usage
=====

.. code-block:: python

	from mwoauth import ConsumerToken, Handshaker
	
	# Construct a "consumer" from the key/secret provided by MediaWiki
	import config
	consumer_token = ConsumerToken(config.consumer_key, config.consumer_secret)
	
	# Construct handshaker with wiki URI and consumer
	handshaker = Handshaker("https://en.wikipedia.org/w/index.php",
	                        consumer_token)
	
	# Step 1: Initialize -- ask MediaWiki for a temporary key/secret for user
	redirect, request_token = handshaker.initiate()
	
	# Step 2: Authorize -- send user to MediaWiki to confirm authorization
	print("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 user
	identity = handshaker.identify(access_token)
	print("Identified as {username}.".format(**identity))