From 45f3e9589d11bee1e75036a7d7b18e18530cc061 Mon Sep 17 00:00:00 2001 From: const Date: Wed, 12 Oct 2011 19:23:44 +0400 Subject: [PATCH 1/2] added google hybrid oauth extension --- openid/extensions/oauth.py | 99 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 openid/extensions/oauth.py diff --git a/openid/extensions/oauth.py b/openid/extensions/oauth.py new file mode 100644 index 00000000..f73627ac --- /dev/null +++ b/openid/extensions/oauth.py @@ -0,0 +1,99 @@ + + +from openid.message import registerNamespaceAlias, \ + NamespaceAliasRegistrationError +from openid.extension import Extension +from openid import oidutil + +try: + basestring #pylint:disable-msg=W0104 +except NameError: + # For Python 2.2 + basestring = (str, unicode) #pylint:disable-msg=W0622 + +ns_uri = "http://specs.openid.net/extensions/oauth/1.0" +# +try: + registerNamespaceAlias(ns_uri, 'oauth') +except NamespaceAliasRegistrationError, e: + oidutil.log('registerNamespaceAlias(%r, %r) failed: %s' % (ns_uri, + 'oauth', str(e),)) + + +class OAuthRequest(Extension): + + ns_alias = 'oauth' + + def __init__(self, consumer=None, scope=None, oauth_ns_uri=ns_uri): + Extension.__init__(self) + self.consumer = consumer + self.scope = scope + self.ns_uri = oauth_ns_uri + + + def fromOpenIDRequest(cls, request): + self = cls() + + args = request.message.getArgs(self.ns_uri) + self.parseExtensionArgs(args) + + return self + + fromOpenIDRequest = classmethod(fromOpenIDRequest) + + def parseExtensionArgs(self, args, strict=False): + + self.consumer = args['consumer'] + self.scope = args['scope'] + + + def getExtensionArgs(self): + args = {} + + if self.consumer: + args['consumer'] = self.consumer + + if self.scope: + args['scope'] = self.scope + + return args + +class OAuthResponse(Extension): + + ns_alias = 'oauth' + + def __init__(self, request_token=None, scope=None): + Extension.__init__(self) + self.ns_uri = ns_uri + self.request_token = request_token + self.scope = scope + + + def fromSuccessResponse(cls, success_response, signed_only=True): + self = cls() + if signed_only: + args = success_response.getSignedNS(ns_uri) + else: + args = success_response.message.getArgs(ns_uri) + + if not args: + return None + + self.request_token = args['request_token'] + self.scope = args['scope'] + + return self + + fromSuccessResponse = classmethod(fromSuccessResponse) + + def getExtensionArgs(self): + args = {} + + if self.consumer: + args['consumer'] = self.consumer + + if self.scope: + args['scope'] = self.scope + + return args + From a4d72cc26ee1d285831c5572cb90fc3a6382ae63 Mon Sep 17 00:00:00 2001 From: certator Date: Wed, 12 Oct 2011 19:26:41 +0400 Subject: [PATCH 2/2] Edited README via GitHub --- README | 69 +--------------------------------------------------------- 1 file changed, 1 insertion(+), 68 deletions(-) diff --git a/README b/README index 98d97e6e..dbf40bc0 100644 --- a/README +++ b/README @@ -1,68 +1 @@ -This is the Python OpenID library. - -REQUIREMENTS -============ - - - Python 2.3, 2.4, or 2.5. - - - ElementTree. This is included in the Python 2.5 standard library, - but users of earlier versions of Python may need to install it - seperately. - - - pycrypto, if on Python 2.3 and without /dev/urandom, or on Python - 2.3 or 2.4 and you want SHA256. - - -INSTALLATION -============ - -To install the base library, just run the following command: - -python setup.py install - -To run setup.py you need the distutils module from the Python standard -library; some distributions package this seperately in a "python-dev" -package. - - -GETTING STARTED -=============== - -The examples directory includes an example server and consumer -implementation. See the README file in that directory for more -information on running the examples. - -Library documentation is available in html form in the doc directory. - - -LOGGING -======= - -This library offers a logging hook that will record unexpected -conditions that occur in library code. If a condition is recoverable, -the library will recover and issue a log message. If it is not -recoverable, the library will raise an exception. See the -documentation for the openid.oidutil module for more on the logging -hook. - - -DOCUMENTATION -============= - -The documentation in this library is in Epydoc format, which is -detailed at: - - http://epydoc.sourceforge.net/ - - -CONTACT -======= - -Send bug reports, suggestions, comments, and questions to -http://openid.net/developers/dev-mailing-lists/. - -If you have a bugfix or feature you'd like to contribute, don't -hesitate to send it to us. For more detailed information on how to -contribute, see - - http://openidenabled.com/contribute/ +added google oauth extension \ No newline at end of file