def twitter_user_api_auth_stage_1(): auth = tweepy.OAuthHandler(get_env("TWITTER_CONSUMER_KEY"), get_env("TWITTER_CONSUMER_SECRET")) redirect_url = auth.get_authorization_url() t = get_twitter_app() t.credentials = {"request_token": auth.request_token} t.save() return redirect_url
def get_tweepy_api_auth(compression=False, wait_on_rate_limit=True, wait_on_rate_limit_notify=True): t = get_twitter_app() if t.credentials is not None and "access_token" in t.credentials and "access_token_secret" in t.credentials: auth = tweepy.OAuthHandler(get_env("TWITTER_CONSUMER_KEY"), get_env("TWITTER_CONSUMER_SECRET")) auth.set_access_token(t.credentials["access_token"], t.credentials["access_token_secret"]) return tweepy.API(auth, compression=compression, wait_on_rate_limit=wait_on_rate_limit, wait_on_rate_limit_notify=wait_on_rate_limit_notify) return None
def twitter_user_api_auth_stage_2(query_params): auth = tweepy.OAuthHandler(get_env("TWITTER_CONSUMER_KEY"), get_env("TWITTER_CONSUMER_SECRET")) t = get_twitter_app() if t.credentials is None or "request_token" not in t.credentials: raise Exception("request_token not available - run auth1 first") if "oauth_verifier" not in query_params: raise Exception("oauth_verifier not available") auth.request_token = { "oauth_token": t.credentials["request_token"]["oauth_token"], "oauth_token_secret": query_params["oauth_verifier"] } auth.get_access_token(query_params["oauth_verifier"]) t.credentials = { "access_token": auth.access_token, "access_token_secret": auth.access_token_secret, } t.save() return True
import os import sentry_sdk from sentry_sdk.integrations.django import DjangoIntegration from scremsong.util import get_env # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = get_env("SECRET_KEY") # Security SECURE_SSL_REDIRECT = True # https://stackoverflow.com/a/22284717 SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') SECURE_CONTENT_TYPE_NOSNIFF = True SECURE_BROWSER_XSS_FILTER = True SESSION_COOKIE_SECURE = True CSRF_COOKIE_SECURE = True X_FRAME_OPTIONS = "DENY" CORS_ALLOW_CREDENTIALS = True if get_env("ENVIRONMENT") == "PRODUCTION": DEBUG = False CONN_MAX_AGE = 50 # Half our max number of PostgreSQL connections
def is_development(): return get_env("ENVIRONMENT") == "DEVELOPMENT"