Skip to content

Commit dc16992

Browse files
committed
New: user can decide scopes to use, when using login() to obtain a new token - defaults to read-only scopes
Ref: #3
1 parent c004b27 commit dc16992

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
setuptools.setup(
44
name = 'WS-API',
55
packages = ['ws_api'],
6-
version = '0.7.0',
6+
version = '0.8.0',
77
license = 'GPL-3.0',
88
description = 'Access your Wealthsimple account using their (GraphQL) API.',
99
author = 'Guillaume Boudreau',

ws_api/wealthsimple_api.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,17 @@ def check_oauth_token(self, persist_session_fct: Optional[Callable[[WSAPISession
147147

148148
raise ManualLoginRequired("OAuth token invalid and cannot be refreshed.")
149149

150+
SCOPE_READ_ONLY = 'invest.read trade.read tax.read'
151+
SCOPE_READ_WRITE = 'invest.read trade.read tax.read invest.write trade.write tax.write'
152+
150153
def login_internal(self, username: str, password: str, otp_answer: str = None,
151-
persist_session_fct: callable = None) -> WSAPISession:
154+
persist_session_fct: callable = None, scope: str = SCOPE_READ_ONLY) -> WSAPISession:
152155
data = {
153156
'grant_type': 'password',
154157
'username': username,
155158
'password': password,
156159
'skip_provision': 'true',
157-
'scope': 'invest.read invest.write trade.read trade.write tax.read tax.write',
160+
'scope': scope,
158161
'client_id': self.session.client_id,
159162
'otp_claim': None,
160163
}
@@ -246,9 +249,9 @@ def get_token_info(self):
246249
return self.session.token_info
247250

248251
@staticmethod
249-
def login(username: str, password: str, otp_answer: str = None, persist_session_fct: callable = None):
252+
def login(username: str, password: str, otp_answer: str = None, persist_session_fct: callable = None, scope: str = SCOPE_READ_ONLY):
250253
ws = WealthsimpleAPI()
251-
return ws.login_internal(username, password, otp_answer, persist_session_fct)
254+
return ws.login_internal(username, password, otp_answer, persist_session_fct, scope)
252255

253256
@staticmethod
254257
def from_token(sess: WSAPISession, persist_session_fct: callable = None):

0 commit comments

Comments
 (0)