auth token in request

This commit is contained in:
Łukasz Jędyk 2022-01-24 21:17:01 +01:00
parent 74b2cd9d91
commit 5ba33a5f0f
3 changed files with 5 additions and 12 deletions

View File

@ -5,4 +5,4 @@ campaign_db = SQLAlchemy()
class TwitterCampaign(campaign_db.Model): class TwitterCampaign(campaign_db.Model):
__tablename__ = 'twitter_campaign' __tablename__ = 'twitter_campaign'
campaign_id = campaign_db.Column(campaign_db.Integer, primary_key=True, nullable=False) campaign_id = campaign_db.Column(campaign_db.Integer, primary_key=True)

View File

@ -30,7 +30,7 @@ def add_twitter_account():
content_type = request.headers.get('Content-Type') content_type = request.headers.get('Content-Type')
if (content_type == 'application/json'): if (content_type == 'application/json'):
json = request.json json = request.json
if not json['veryfier']: if not json['veryfier'] or not json['oauth_token'] or not json['oauth_token_secret']:
return Response( return Response(
"Invalid request!", "Invalid request!",
status=400, status=400,
@ -39,19 +39,12 @@ def add_twitter_account():
consumer_key = current_app.config["TWITTER_CONSUMER_KEY"] consumer_key = current_app.config["TWITTER_CONSUMER_KEY"]
consumer_secret = current_app.config["TWITTER_CONSUMER_SECERT"] consumer_secret = current_app.config["TWITTER_CONSUMER_SECERT"]
oauth = OAuth1Session(
consumer_key,
client_secret=consumer_secret
)
request_token_url = "https://api.twitter.com/oauth/request_token?oauth_callback=oob&x_auth_access_type=write"
fetch_response = oauth.fetch_request_token(request_token_url)
access_token_url = "https://api.twitter.com/oauth/access_token" access_token_url = "https://api.twitter.com/oauth/access_token"
oauth = OAuth1Session( oauth = OAuth1Session(
consumer_key, consumer_key,
client_secret=consumer_secret, client_secret=consumer_secret,
resource_owner_key=fetch_response.get("oauth_token"), resource_owner_key=json['oauth_token'],
resource_owner_secret=fetch_response.get("oauth_token_secret"), resource_owner_secret=json['oauth_token_secret'],
verifier=json['veryfier'], verifier=json['veryfier'],
) )
oauth_tokens = oauth.fetch_access_token(access_token_url) oauth_tokens = oauth.fetch_access_token(access_token_url)

View File

@ -6,7 +6,7 @@ twitter_db = SQLAlchemy()
class TwitterAccount(twitter_db.Model): class TwitterAccount(twitter_db.Model):
__tablename__ = 'twitter_account' __tablename__ = 'twitter_account'
account_id = twitter_db.Column(twitter_db.Integer, primary_key=True, nullable=False) account_id = twitter_db.Column(twitter_db.Integer, primary_key=True)
twitter_user_id = twitter_db.Column(twitter_db.String(16), unique=True, nullable=False) twitter_user_id = twitter_db.Column(twitter_db.String(16), unique=True, nullable=False)
username = twitter_db.Column(twitter_db.String(16), unique=True, nullable=False) username = twitter_db.Column(twitter_db.String(16), unique=True, nullable=False)
access_token = twitter_db.Column(twitter_db.String(256), nullable=False) access_token = twitter_db.Column(twitter_db.String(256), nullable=False)