예제 #1
0
def dropbox_auth_finish(return_access_token=False):
    app_details = get_dropbox_settings(redirect_uri=True)
    callback = frappe.form_dict
    close = '<p class="text-muted">' + _("Please close this window") + "</p>"

    dropbox_oauth_flow = dropbox.DropboxOAuth2Flow(
        consumer_key=app_details["app_key"],
        redirect_uri=app_details["redirect_uri"],
        session={"dropbox-auth-csrf-token": callback.state},
        csrf_token_session_key="dropbox-auth-csrf-token",
        consumer_secret=app_details["app_secret"],
    )

    if callback.state or callback.code:
        token = dropbox_oauth_flow.finish({
            "state": callback.state,
            "code": callback.code
        })
        if return_access_token and token.access_token:
            return token.access_token, callback.state

        set_dropbox_access_token(token.access_token)
    else:
        frappe.respond_as_web_page(
            _("Dropbox Setup"),
            _("Illegal Access Token. Please try again") + close,
            indicator_color="red",
            http_status_code=frappe.AuthenticationError.http_status_code,
        )

    frappe.respond_as_web_page(_("Dropbox Setup"),
                               _("Dropbox access is approved!") + close,
                               indicator_color="green")
예제 #2
0
def dropbox_auth_finish(return_access_token=False):
    app_details = get_dropbox_settings(redirect_uri=True)
    callback = frappe.form_dict
    close = '<p class="text-muted">' + _('Please close this window') + '</p>'

    dropbox_oauth_flow = dropbox.DropboxOAuth2Flow(
        app_details["app_key"], app_details["app_secret"],
        app_details["redirect_uri"],
        {'dropbox-auth-csrf-token': callback.state}, "dropbox-auth-csrf-token")

    if callback.state or callback.code:
        token = dropbox_oauth_flow.finish({
            'state': callback.state,
            'code': callback.code
        })
        if return_access_token and token.access_token:
            return token.access_token, callback.state

        set_dropbox_access_token(token.access_token)
    else:
        frappe.respond_as_web_page(
            _("Dropbox Setup"),
            _("Illegal Access Token. Please try again") + close,
            indicator_color='red',
            http_status_code=frappe.AuthenticationError.http_status_code)

    frappe.respond_as_web_page(_("Dropbox Setup"),
                               _("Dropbox access is approved!") + close,
                               indicator_color='green')
예제 #3
0
def build_flow(session):
    return dropbox.DropboxOAuth2Flow(
        current_app.config["DROPBOX_APP_KEY"],
        url_for("user.setting_dropbox_oauth_callback", _external=True),
        session,
        current_app.config["SECRET_KEY"],
        consumer_secret=current_app.config["DROPBOX_APP_SECRET"],
    )
예제 #4
0
def _new_dbx_auth_flow(session):
    return dropbox.DropboxOAuth2Flow(
        _APP.config['DBX_APP_KEY'],
        _APP.config['DBX_APP_SECRET'],
        urljoin(_APP.config['BASE_URL'], flask.url_for('route_finish')),
        session,
        'dbx-auth-csrf-token',
    )
예제 #5
0
    def _oauth2_flow(self, full, session):
        app_credentials = self._app_credentials(full)

        redirect_uri = WEB_ROOT + reverse("oauth_return",
                                          kwargs={"service": "dropbox", "level": "full" if full else "normal"})
        return dropbox.DropboxOAuth2Flow(
            app_credentials[0], app_credentials[1], redirect_uri, session,
            "dropbox-auth-csrf-token")
예제 #6
0
def get_dropbox_authorize_url():
    app_details = get_dropbox_settings(redirect_uri=True)
    dropbox_oauth_flow = dropbox.DropboxOAuth2Flow(app_details["app_key"],
                                                   app_details["app_secret"],
                                                   app_details["redirect_uri"],
                                                   {},
                                                   "dropbox-auth-csrf-token")

    auth_url = dropbox_oauth_flow.start()

    return {"auth_url": auth_url, "args": parse_qs(urlparse(auth_url).query)}
예제 #7
0
def get_dropbox_authorize_url():
    app_details = get_dropbox_settings(redirect_uri=True)
    dropbox_oauth_flow = dropbox.DropboxOAuth2Flow(
        consumer_key=app_details["app_key"],
        redirect_uri=app_details["redirect_uri"],
        session={},
        csrf_token_session_key="dropbox-auth-csrf-token",
        consumer_secret=app_details["app_secret"])

    auth_url = dropbox_oauth_flow.start()

    return {"auth_url": auth_url, "args": parse_qs(urlparse(auth_url).query)}