Exemplo n.º 1
0
            def auth_handler():
                try:
                    token, payload = self.provider.authenticate(bottle.request)
                    string_token = token.decode("utf-8")

                    if (self.provider.auth_redirect_rule is not None
                        ) and self.provider.auth_redirect_rule():
                        response = self.get_redirect_response_object(
                            self.provider.auth_redirect_to)

                        if self.provider.on_auth_redirect:
                            response = self.provider.on_auth_redirect(response)

                    else:
                        json_payload = {
                            "access_token": string_token,
                            "scope": payload["scope"],
                            "token_type": "bearer",
                            "expires_in": self.provider.ttl
                        }

                        response_headers = {
                            "Authorization": "Bearer " + string_token,
                            "Authorization-Scope": payload["scope"],
                            "Authorization-Token-Type": "bearer",
                            "Authorization-Expires-In": self.provider.ttl
                        }

                        response = HTTPResponse(status=200,
                                                body=json_payload,
                                                headers=response_headers)

                    response.set_cookie("Authorization",
                                        "Bearer " + string_token,
                                        max_age=self.provider.ttl,
                                        path=self.provider.cookie_path,
                                        secret=self.provider.cookie_secret)

                    return response

                except JWTAuthError as error:
                    return {"AuthError": error.args[0]}

                except JWTBackendError:
                    return {"AuthBackendError": "Try later or contact admin!"}
Exemplo n.º 2
0
def dropbox_auth():
    """
    Get Dropbox oatuh tokens
    """
    storage = SettingStorage(SETTINGS_FILE)
    consumer_key = storage.get('dropbox:consumer_key')
    consumer_secret = storage.get('dropbox:consumer_secret')
    sess = session.DropboxSession(consumer_key, consumer_secret, 'app_folder')

    request_token = sess.obtain_request_token()

    callback = "%s://%s/dropbox/auth/callback" % (request.urlparts.scheme, request.urlparts.netloc)
    auth_url = sess.build_authorize_url(request_token, callback)
    # response.set_cookie('request_token', '&'.join([request_token.key, request_token.secret]))

    resp = HTTPResponse("", status=302, Location=auth_url)
    resp.set_cookie('request_token', '&'.join([request_token.key, request_token.secret]))
    return resp
Exemplo n.º 3
0
def set():
    resp = HTTPResponse(status=303)
    resp.set_header('Location','/')
    resp.set_cookie('account', 'admin', secret='ThisIsSecretKey')
    return resp
Exemplo n.º 4
0
def json_response(status_code: int, body: dict, cookie: str = None) -> HTTPResponse:
    response = HTTPResponse(status=status_code, body=json.dumps(body, ensure_ascii=False))
    response.set_header("Content-Type", "application/json")
    if cookie is not None:
        response.set_cookie("user_id", cookie, max_age=60*60*24*7)
    return response