Exemple #1
0
def OpenIDFinish(request, default_success_url='/', success_handler=None):
    if request.method not in ('GET', 'POST'):
        return HttpResponseNotAllowed(['GET', 'POST'])
    else:
        args = args_to_dict(request.GET)
        assert type(args) is dict
        if request.method == 'POST':
            args.update(args_to_dict(request.POST))
        url = 'http://' + request.META['HTTP_HOST'] + reverse(OpenIDFinish)

        s = {}
        sess_key = request.COOKIES.get(COOKIE_NAME, None)
        if sess_key:
            s = store.restoreConsumerSession(sess_key)

        c = Consumer(s, store.DatastoreStore())
        auth_response = c.complete(args, url)

        if auth_response.status == auth_SUCCESS:

            openid_url = auth_response.getDisplayIdentifier()
            continueUrl = get_continue_url(request, default_success_url)
            response = HttpResponseRedirect(continueUrl)

            if success_handler:
                success_handler(request, response, openid_url)

            return response

        else:
            return err_page("verification_failed")
Exemple #2
0
def InitializeOpenId():
    global oidserver
    name = os.environ.get('SERVER_NAME', None)
    port = os.environ.get('SERVER_PORT', '80')
    op_endpoint = "http://%s%s/server" % (
        name, ":%s" % port if port != "80" else "") if name else None
    logging.info('op_endpoint: %s', op_endpoint)
    oidserver = OpenIDServer.Server(store.DatastoreStore(),
                                    op_endpoint=op_endpoint)
Exemple #3
0
    def get_consumer(self):
        """Returns a Consumer instance.
    """
        if not self.consumer:
            fetchers.setDefaultFetcher(fetcher.UrlfetchFetcher())
            if not self.load_session():
                return
            self.consumer = Consumer(self.session_args, store.DatastoreStore())

        return self.consumer
Exemple #4
0
def initialize_open_id():
    """
    Initialize and set the global OpenID protocol server.
    """
    global oidserver
    if oidserver is None:
        # We have to use os.environ, the server uses it.
        name = os.environ.get('SERVER_NAME', None)
        port = os.environ.get('SERVER_PORT', '80')
        op_endpoint = "http://%s%s/server" % (
            name, ":%s" % port if port != "80" else "") if name else None
        logging.info('op_endpoint: %s', op_endpoint)
        oidserver = OpenIDServer.Server(store.DatastoreStore(),
                                        op_endpoint=op_endpoint)
Exemple #5
0
def OpenIDStartSubmit(request, default_success_url='/', success_handler=None):
    response = HttpResponse()
    openid = request.REQUEST.get('openid_identifier', '').strip()
    if not openid:
        return err_page("no_openid_identifier")

    c = Consumer({}, store.DatastoreStore())
    try:
        auth_request = c.begin(openid)

    except discover.DiscoveryFailure, e:
        return err_page("server_discovery",
                        msg='OpenID discovery error with begin on %s: %s' %
                        (openid, str(e)))
Exemple #6
0
def get_store():
  return store.DatastoreStore()
Exemple #7
0
import urlparse
import wsgiref.handlers

from google.appengine.api import datastore
from google.appengine.api import users
from google.appengine.ext.webapp import template
import webapp2

from openid.server import server as OpenIDServer
import store

# Set to True if stack traces should be shown in the browser, etc.
_DEBUG = False

# the global openid server instance
oidserver = OpenIDServer.Server(store.DatastoreStore())


class Handler(webapp2.RequestHandler):
    """A base handler class with a couple OpenID-specific utilities."""
    def ArgsToDict(self):
        """Converts the URL and POST parameters to a singly-valued dictionary.

    Returns:
      dict with the URL and POST body parameters
    """
        req = self.request
        return dict([(arg, req.get(arg)) for arg in req.arguments()])

    def HasCookie(self):
        """Returns True if we "remember" the user, False otherwise.
Exemple #8
0
def InitializeOpenId():
  global oidserver
  oidserver = OpenIDServer.Server(store.DatastoreStore())