Exemplo n.º 1
0
    def validate_redirect_uri(self, client_id, redirect_uri):
        internal_redirect_url = '%s%s' % (get_app_url(
            config.app_config), url_for('web.oauth_local_handler'))

        if redirect_uri == internal_redirect_url:
            return True

        try:
            oauth_app = OAuthApplication.get(client_id=client_id)
            if (oauth_app.redirect_uri and redirect_uri
                    and redirect_uri.startswith(oauth_app.redirect_uri)):
                return True
            return False
        except OAuthApplication.DoesNotExist:
            return False
Exemplo n.º 2
0
    def prepare_for_drop(self, mime_type, requires_cors=True):
        """ Returns a signed URL to upload a file to our bucket. """
        logger.debug('Requested upload url with content type: %s' % mime_type)
        file_id = str(uuid4())
        path = self.get_file_id_path(file_id)
        url = self._storage.get_direct_upload_url(self._locations, path,
                                                  mime_type, requires_cors)

        if url is None:
            if self._handler_name is None:
                raise MissingHandlerException()

            with self._app.app_context() as ctx:
                ctx.url_adapter = self._build_url_adapter()
                file_relative_url = url_for(self._handler_name,
                                            file_id=file_id)
                file_url = urlparse.urljoin(get_app_url(self._app.config),
                                            file_relative_url)
                return (file_url, file_id)

        return (url, file_id)
Exemplo n.º 3
0
    def get_file_url(self,
                     file_id,
                     remote_ip,
                     expires_in=300,
                     requires_cors=False):
        path = self.get_file_id_path(file_id)
        url = self._storage.get_direct_download_url(self._locations, path,
                                                    remote_ip, expires_in,
                                                    requires_cors)

        if url is None:
            if self._handler_name is None:
                raise MissingHandlerException()

            with self._app.app_context() as ctx:
                ctx.url_adapter = self._build_url_adapter()
                file_relative_url = url_for(self._handler_name,
                                            file_id=file_id)
                return urllib.parse.urljoin(get_app_url(self._app.config),
                                            file_relative_url)

        return url