Skip to content

Commit e235b66

Browse files
authored
Merge pull request #194 from kostou/kt_oaoth2_allow_access_token_authentication
Add new auth_method 'oauth2-existingaccesstoken'
2 parents 19688f1 + b29e726 commit e235b66

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ client ID and secret alongside your credentials:
9696
>>> t1 = T1(auth_method='oauth2-resourceowner', client_id="my_client_id", client_secret="my_secret", username="my@user", password="mypass")
9797
```
9898

99+
If you already have a valid access token (e.g. by following the authorization code flow - outside this library), you can also pass it in order to get authenticated:
100+
``` {.python}
101+
>>> t1 = t1 = terminalone.T1(access_token=token, environment=environment, auth_method='oauth2-existingaccesstoken', json=True)
102+
```
103+
99104
If you have a specific API base (for instance, if you are testing
100105
against a sandbox deployment) (*Note*: sandbox environments are not yet
101106
useable), you can use the `api_base` keyword with the *domain*. For

terminalone/connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ def _create_session(self):
7171
method = self.auth_params['method']
7272
session = Session()
7373
session.headers['User-Agent'] = self.user_agent
74-
if method != 'oauth2-resourceowner':
74+
if method not in ['oauth2-resourceowner',
75+
'oauth2-existingaccesstoken']:
7576
session.params = {'api_key': self.auth_params['api_key']}
7677
if self.json:
7778
session.headers['Accept'] = ACCEPT_HEADERS['json']

terminalone/service.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,23 @@ def authenticate(self, auth_method, **kwargs):
125125
session_id = kwargs.get('session_id')
126126
access_token = kwargs.get('access_token')
127127
if session_id is not None and auth_method in ['cookie',
128-
'oauth2-resourceowner']:
128+
'oauth2-resourceowner',
129+
'oauth2-existingaccesstoken']:
129130
return super(T1, self)._auth_session_id(
130131
session_id,
131132
self.auth_params['api_key']
132133
)
133134

134-
if access_token is not None and auth_method in ['oauth2-resourceowner']:
135+
if access_token is not None and auth_method in ['oauth2-resourceowner',
136+
'oauth2-existingaccesstoken']:
135137
return super(T1, self)._auth_access_token(access_token)
136138

137139
if auth_method == 'cookie':
138140
return super(T1, self)._auth_cookie(self.auth_params['username'],
139141
self.auth_params['password'],
140142
self.auth_params['api_key'])
141-
elif auth_method == 'oauth2-resourceowner':
143+
elif auth_method in ['oauth2-resourceowner',
144+
'oauth2-existingaccesstoken']:
142145
return super(T1, self).fetch_resource_owner_password_token(
143146
self.auth_params['username'],
144147
self.auth_params['password'],

0 commit comments

Comments
 (0)