Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save token to token.txt for reuse. #134

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,5 @@ ENV/
.ropeproject

# Personal load details
config.json
config.json
token.txt
24 changes: 14 additions & 10 deletions pgoapi/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,44 @@

import logging


class Auth:

def __init__(self):
self.log = logging.getLogger(__name__)

self._auth_provider = None

self._login = False
self._auth_token = None

self._ticket_expire = None
self._ticket_start = None
self._ticket_end = None

def get_name(self):
return self._auth_provider

def is_login(self):
return self._login

def get_token(self):
return self._auth_token


def set_token(self, auth_token):
self._auth_token = auth_token

def has_ticket(self):
if self._ticket_expire and self._ticket_start and self._ticket_end:
return True
else:
return False

def set_ticket(self, params):
self._ticket_expire, self._ticket_start, self._ticket_end = params

def get_ticket(self):
if self.has_ticket():
return (self._ticket_expire, self._ticket_start, self._ticket_end)
else:
return False
return False
18 changes: 12 additions & 6 deletions pgoapi/pgoapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import requests
import six

from .utilities import f2i, h2f
from pgoapi.rpc_api import RpcApi
from pgoapi.auth_ptc import AuthPtc
from pgoapi.auth_google import AuthGoogle
Expand Down Expand Up @@ -127,8 +126,7 @@ def function(**kwargs):
else:
raise AttributeError


def login(self, provider, username, password):
def login(self, provider, username, password, auth_token=None):

if not isinstance(username, six.string_types) or not isinstance(password, six.string_types):
raise AuthException("Username/password not correctly specified")
Expand All @@ -142,9 +140,17 @@ def login(self, provider, username, password):

self.log.debug('Auth provider: %s', provider)

if not self._auth_provider.login(username, password):
self.log.info('Login process failed')
return False
if auth_token is None:
if not self._auth_provider.login(username, password):
self.log.info('Login process failed')
return False
with open("token.txt", "w") as f:

Choose a reason for hiding this comment

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

need to find a proper place to path this, man.... just this relative path is not good

f.write(self._auth_provider.get_token())
self.log.info('Token saved')
else:
self.log.info('Reuse token')
self._auth_provider._login = True
self._auth_provider.set_token(auth_token)

self.log.info('Starting RPC login sequence (app simulation)')

Expand Down