Exemplo n.º 1
0
def get_auth_headers():
  auth = load_auth()
  secrets = load_secrets()
  # TODO: refresh if expired or about to expire
  return {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ' + auth['access_token'],
    'trakt-api-version': '2',
    'trakt-api-key': secrets['CLIENT_ID'],
  }
Exemplo n.º 2
0
 def pin_request(self, pin):
   secrets = load_secrets()
   headers = {
     'Content-Type': 'application/json'
   }
   data = {
     'code': pin,
     'client_id': secrets['CLIENT_ID'],
     'client_secret': secrets['CLIENT_SECRET'],
     'redirect_uri': 'urn:ietf:wg:oauth:2.0:oob',
     'grant_type': 'authorization_code',
   }
   return self.req('POST', '/oauth/token', headers=headers, data=simplejson.dumps(data))
Exemplo n.º 3
0
def auth_flow(**kwargs):
    api = TraktTvApi()

    secrets = load_secrets()
    pin_url = PIN_URL % secrets[PIN_ID]

    print "Head to %s to authenticate and enter your PIN below:" % pin_url
    pin = raw_input("PIN: ")
    while not pin_valid(pin):
        pin = raw_input("PIN: ")

    response = api.pin_request(pin)

    with open(AUTH_PATH, "w") as auth_file:
        expires = datetime.datetime.utcnow() + datetime.timedelta(seconds=response["expires_in"])
        response["expires_on"] = expires.isoformat()
        simplejson.dump(response, auth_file, indent=2)
    print "Successfully authenticated."