Skip to content
This repository was archived by the owner on Jan 11, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions gistey/auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import requests
import datetime
import time
import getpass
from functools import partial

end = "https://api.github.com/"


def authorize(func):
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completely remove it for now, if needed we will introduce in future

"""
Authorize application

:param func:
function to decorate for required authorization.
"""

username = input('Enter GitHub Username: ')
password = getpass.getpass()
return partial(func, auth=(username, password))


@authorize
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be a problem in making authorize function as the decorator.
Because currently, the decorator right away asks for username and password instead of asking at function call.

def create_token(end, auth):
"""
Get the Personal access token or create one if not exists already.

:param end:
End point of the API.
:param auth:
A tuple consisting of username and password
"""

params = {
"scope": ["gist"],
"note": "gistey"
}

rq = requests.post(end + "authorizations/", params=params, auth=auth)

if "X-GitHub-OTP" in rq.headers:
otp = input("Enter 2FA code: ")
rq = requests.put(end + "authorizations/", params=params, auth=auth,
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to post

headers={"X-GitHub-OTP": otp})

return rq
# TODO Returns 404 =/ Confusing