def buildURL(self, txrequest, action='', **query): """Build a URL relative to the server base_url, with the given query parameters added.""" base = '//%s/%s/' % (self.eventhandler.url, '/'.join(txrequest.prepath)) if not base: a = urlparse.urlparse(txrequest.prePathURL()+'/') port = a.port if self.eventhandler.external_port: port = self.eventhandler.external_port if port == 80: port = '' else: port = ':%s' % port url = urlparse.SplitResult( a.scheme, '%s:%s@%s%s' % ( a.username, a.password, a.hostname, port ), a.path, a.query, a.fragment) base = url.geturl() if action: base = urlparse.urljoin(base, action) print 'buildURL', base return appendArgs(base, query)
def encodeToURL(self, server_url): """Encode this request as a URL to GET. @param server_url: The URL of the OpenID server to make this request of. @type server_url: str @returntype: str """ # Imported from the alternate reality where these classes are used # in both the client and server code, so Requests are Encodable too. # That's right, code imported from alternate realities all for the # love of you, id_res/user_setup_url. q = { 'mode': self.mode, 'identity': self.identity, 'return_to': self.return_to } if self.trust_root: q['trust_root'] = self.trust_root if self.assoc_handle: q['assoc_handle'] = self.assoc_handle q = dict([(OPENID_PREFIX + k, v) for k, v in q.iteritems()]) return oidutil.appendArgs(server_url, q)
def buildURL(self, txrequest, action='', **query): """Build a URL relative to the server base_url, with the given query parameters added.""" base = '//%s/%s/' % (self.eventhandler.url, '/'.join( txrequest.prepath)) if not base: a = urlparse.urlparse(txrequest.prePathURL() + '/') port = a.port if self.eventhandler.external_port: port = self.eventhandler.external_port if port == 80: port = '' else: port = ':%s' % port url = urlparse.SplitResult( a.scheme, '%s:%s@%s%s' % (a.username, a.password, a.hostname, port), a.path, a.query, a.fragment) base = url.geturl() if action: base = urlparse.urljoin(base, action) print 'buildURL', base return appendArgs(base, query)
def post_user_info(request_user_metadata): logging.debug( "login_openid post_user_info, request_user_metadata: {0}". format(request_user_metadata)) oid_consumer = consumer.Consumer(self.get_openid_session(request), self.store) try: oid_req = oid_consumer.begin(identity) if request_user_metadata: # SReg speaks this protocol: http://openid.net/specs/openid-simple-registration-extension-1_1-01.html # and tries to request additional metadata about this OpenID identity sreg_req = sreg.SRegRequest( required=['fullname', 'nickname', 'email'], optional=[]) oid_req.addExtension(sreg_req) # AX speaks this protocol: http://openid.net/specs/openid-attribute-exchange-1_0.html # and tries to get more attributes (by URI), we request some of the more common ones ax_req = ax.FetchRequest() for uri in self.AX_URIS: ax_req.add(ax.AttrInfo(uri, required=True)) oid_req.addExtension(ax_req) except consumer.DiscoveryFailure as exc: logging.error("Error in login_openid: {0}".format(exc)) self._send_openid_redirect(request, { "status": 401, "message": "Unauthorized" }) return else: if oid_req is None: logging.error( "Error in login_openid: no OpenID services found for: {0}" .format(identity)) self._send_openid_redirect(request, { "status": 401, "message": "Unauthorized" }) return else: trust_root = self.webserver.server_url return_to = appendArgs( trust_root + "/" + self.base_path + "/openid_process", {}) logging.debug( "OpenID, had oid_req, trust_root: {0}, return_to: {1}, oid_req: {2}" .format(trust_root, return_to, oid_req)) redirect_url = oid_req.redirectURL(trust_root, return_to) request.setHeader("Location", redirect_url) request.setResponseCode(302, "Found") request.finish() return
def redirectURL(self, trust_root, return_to, immediate=False): if immediate: mode = 'checkid_immediate' else: mode = 'checkid_setup' return_to = oidutil.appendArgs(return_to, self.return_to_args) redir_args = { 'openid.mode': mode, 'openid.identity': self.endpoint.getServerID(), 'openid.return_to': return_to, 'openid.trust_root': trust_root, } if self.assoc: redir_args['openid.assoc_handle'] = self.assoc.handle redir_args.update(self.extra_args) return oidutil.appendArgs(self.endpoint.server_url, redir_args)
def encodeToURL(self): """Encode a response as a URL for the user agent to GET. You will generally use this URL with a HTTP redirect. @returns: A URL to direct the user agent back to. @returntype: str """ fields = dict([(OPENID_PREFIX + k, v.encode('UTF8')) for k, v in self.fields.iteritems()]) return oidutil.appendArgs(self.request.return_to, fields)
def encodeToURL(self): """Encode a response as a URL for the user agent to GET. You will generally use this URL with a HTTP redirect. @returns: A URL to direct the user agent back to. @returntype: str """ fields = dict( [(OPENID_PREFIX + k, v.encode('UTF8')) for k, v in self.fields.iteritems()]) return oidutil.appendArgs(self.request.return_to, fields)
def start_openid_auth(request, openid_url): form = request.getForm() config = request.getConfiguration() data = request.getData() import_and_initialize() # Try to start OpenID verification session = Session(request) consumer = get_openid_consumer(request, session) if consumer is None: return if check_url_rejected(config, openid_url, 'identity'): tools.getLogger().info('Rejected %r' % (openid_url, )) raise OpenIDCommentError( 'That identity is not allowed to post to this blog') auth_req = consumer.begin(openid_url) # Make sure that the server and identity URL are allowed by the config server_id = auth_req.endpoint.getLocalID() server_url = auth_req.endpoint.server_url if (check_url_rejected(config, server_id, 'identity') or check_url_rejected(config, server_url, 'server')): tools.getLogger().info('Rejected %r or %r' % (server_id, server_url)) raise OpenIDCommentError( 'That identity is not allowed to post to this blog') if 'body' not in form: raise OpenIDCommentError('Comment body required') if 'openid_trust_root' in config: trust_root = config['openid_trust_root'] else: trust_root = config['base_url'] # Save the data for the return populate_comment_session(session, request, auth_req.assoc, trust_root) args = { sid_field: session.id(), 'showcomments': 'yes', } return_to = appendArgs(data['url'], args) redirect_url = auth_req.redirectURL(trust_root, return_to) renderer = data['renderer'] renderer.addHeader('Status', '302 Found') renderer.addHeader("Location", redirect_url) renderer.showHeaders() renderer.rendered = 1
def encodeToURL(self): """Encode a response as a URL for the user agent to GET. You will generally use this URL with a HTTP redirect. @returns: A URL to direct the user agent back to. @returntype: str """ return_to = self.query.get(OPENID_PREFIX + 'return_to') if not return_to: raise ValueError("I have no return_to URL.") return oidutil.appendArgs(return_to, { 'openid.mode': 'error', 'openid.error': str(self), })
def start_openid_auth(request, openid_url): form = request.getForm() config = request.getConfiguration() data = request.getData() import_and_initialize() # Try to start OpenID verification session = Session(request) consumer = get_openid_consumer(request, session) if consumer is None: return if check_url_rejected(config, openid_url, 'identity'): tools.getLogger().info('Rejected %r' % (openid_url,)) raise OpenIDCommentError( 'That identity is not allowed to post to this blog') auth_req = consumer.begin(openid_url) # Make sure that the server and identity URL are allowed by the config server_id = auth_req.endpoint.getLocalID() server_url = auth_req.endpoint.server_url if (check_url_rejected(config, server_id, 'identity') or check_url_rejected(config, server_url, 'server')): tools.getLogger().info('Rejected %r or %r' % (server_id, server_url)) raise OpenIDCommentError( 'That identity is not allowed to post to this blog') if 'body' not in form: raise OpenIDCommentError('Comment body required') if 'openid_trust_root' in config: trust_root = config['openid_trust_root'] else: trust_root = config['base_url'] # Save the data for the return populate_comment_session(session, request, auth_req.assoc, trust_root) args = {sid_field: session.id(), 'showcomments': 'yes',} return_to = appendArgs(data['url'], args) redirect_url = auth_req.redirectURL(trust_root, return_to) renderer = data['renderer'] renderer.addHeader('Status', '302 Found') renderer.addHeader("Location", redirect_url) renderer.showHeaders() renderer.rendered = 1
def getCancelURL(self): """Get the URL to cancel this request. Useful for creating a "Cancel" button on a web form so that operation can be carried out directly without another trip through the server. (Except you probably want to make another trip through the server so that it knows that the user did make a decision. Or you could simulate this method by doing C{.answer(False).encodeToURL()}) @returntype: str @returns: The return_to URL with openid.mode = cancel. """ if self.immediate: raise ValueError("Cancel is not an appropriate response to " "immediate mode requests.") return oidutil.appendArgs(self.return_to, {OPENID_PREFIX + 'mode': 'cancel'})
def post_pw(): logging.debug("login_openid post_pw") oid_consumer = consumer.Consumer(self.get_openid_session(request), self.store) try: oid_req = oid_consumer.begin(identity) # SReg speaks this protocol: http://openid.net/specs/openid-simple-registration-extension-1_1-01.html # and tries to request additional metadata about this OpenID identity sreg_req = sreg.SRegRequest(required=['fullname','nickname','email'], optional=[]) oid_req.addExtension(sreg_req) # AX speaks this protocol: http://openid.net/specs/openid-attribute-exchange-1_0.html # and tries to get more attributes (by URI), we request some of the more common ones ax_req = ax.FetchRequest() for uri in self.AX_URIS: ax_req.add(ax.AttrInfo(uri, required = True)) oid_req.addExtension(ax_req) except consumer.DiscoveryFailure as exc: #request.setResponseCode(200, message = "OK") #request.write("Error: {0}".format(exc)) #request.finish() logging.error("Error in login_openid: {0}".format(exc)) return self.return_unauthorized(request) else: if oid_req is None: #request.setResponseCode(200, message = "OK") #request.write("Error, no OpenID services found for: {0}".format(identity)) logging.error("Error in login_openid: no OpenID services found for: {0}".format(identity)) #request.finish() return self.return_unauthorized(request) else: trust_root = self.webserver.server_url return_to = appendArgs(trust_root + "/" + self.base_path + "/openid_process", {}) logging.debug("OpenID, had oid_req, trust_root: {0}, return_to: {1}, oid_req: {2}".format(trust_root, return_to, oid_req)) redirect_url = oid_req.redirectURL(trust_root, return_to) # FIXME check this is the best way to redirect here request.setHeader("Location", redirect_url) request.setResponseCode(302, "Found") request.finish() return
def encodeToURL(self, server_url): """Encode this request as a URL to GET. @param server_url: The URL of the OpenID server to make this request of. @type server_url: str @returntype: str """ # Imported from the alternate reality where these classes are used # in both the client and server code, so Requests are Encodable too. # That's right, code imported from alternate realities all for the # love of you, id_res/user_setup_url. q = {'mode': self.mode, 'identity': self.identity, 'return_to': self.return_to} if self.trust_root: q['trust_root'] = self.trust_root if self.assoc_handle: q['assoc_handle'] = self.assoc_handle q = dict([(OPENID_PREFIX + k, v) for k, v in q.iteritems()]) return oidutil.appendArgs(server_url, q)
def buildURL(self, action, **query): base = urlparse.urljoin(self.base_openid_url, action) return appendArgs(base, query)
def build_url(self, request, action, **query): """Build a URL relative to the server base_url, with the given query parameters added.""" base = urlparse.urljoin(request['base_url'], self.auth_prefix + '/' + action) return appendArgs(base, query)
def toURL(self, base_url): """Generate a GET URL with the parameters in this message attached as query parameters.""" return oidutil.appendArgs(base_url, self.toPostArgs())
def buildURL(self, action, **query): """Build a URL relative to the server base_url, with the given query parameters added.""" base = urlparse.urljoin(self.server.base_url, action) return appendArgs(base, query)
def build_url(self, request, action, **query): """Build a URL relative to the server base_url, with the given query parameters added.""" base = urllib.parse.urljoin(request["base_url"], self.auth_prefix + "/" + action) return appendArgs(base, query)
def buildurl(self, environ, action, **query): '''Build a URL relative to the server base url, with the given query parameters added.''' base = urlparse.urljoin(environ['openid.baseurl'], action) return appendArgs(base, query)
def runTest(self): for name, args, expected in append_args_cases: result = oidutil.appendArgs(*args) self.assertEqual(expected, result, '{} {}'.format(name, args))
def runTest(self): result = oidutil.appendArgs(*self.args) self.assertEqual(self.expected, result, self.args)
def buildURL(self, action, **query): """Build a URL relative to the server base_url, with the given query parameters added.""" # ugly hacks that work work base = self.server.base_url + '/' + action return appendArgs(base, query)