Skip to content

Commit 21cf33c

Browse files
committed
Support new style token-based authentication
Phabricator has moved on from the clunky user+certificate-based authentication scheme into one that provides the API user with a single token that can be used directly. This change adds support for that and prefers it when available. Fixes disqus#22.
1 parent b399e20 commit 21cf33c

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

phabricator/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,15 +309,19 @@ class Phabricator(Resource):
309309
}
310310

311311
def __init__(self, username=None, certificate=None, host=None,
312-
timeout=5, response_format='json', **kwargs):
312+
timeout=5, response_format='json', token=None, **kwargs):
313313

314314
# Set values in ~/.arcrc as defaults
315315
if ARCRC:
316316
self.host = host if host else ARCRC['hosts'].keys()[0]
317-
self.username = username if username else ARCRC['hosts'][self.host]['user']
318-
self.certificate = certificate if certificate else ARCRC['hosts'][self.host]['cert']
317+
if token or ARCRC['hosts'][self.host].has_key('token'):
318+
self.token = token if token else ARCRC['hosts'][self.host]['token']
319+
else:
320+
self.username = username if username else ARCRC['hosts'][self.host]['user']
321+
self.certificate = certificate if certificate else ARCRC['hosts'][self.host]['cert']
319322
else:
320323
self.host = host
324+
self.token = token
321325
self.username = username
322326
self.certificate = certificate
323327

@@ -334,6 +338,12 @@ def _request(self, **kwargs):
334338
raise SyntaxError('You cannot call the Conduit API without a resource.')
335339

336340
def connect(self):
341+
if self.token:
342+
self.conduit = {
343+
'token': self.token
344+
}
345+
return
346+
337347
auth = Resource(api=self, method='conduit', endpoint='connect')
338348

339349
response = auth(user=self.username, host=self.host,

phabricator/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
'maniphest.find': '{"result":{"PHID-TASK-4cgpskv6zzys6rp5rvrc":{"id":"722","phid":"PHID-TASK-4cgpskv6zzys6rp5rvrc","authorPHID":"PHID-USER-5022a9389121884ab9db","ownerPHID":"PHID-USER-5022a9389121884ab9db","ccPHIDs":["PHID-USER-5022a9389121884ab9db","PHID-USER-ba8aeea1b3fe2853d6bb"],"status":"3","priority":"Needs Triage","title":"Relations should be two-way","description":"When adding a differential revision you can specify Maniphest Tickets to add the relation. However, this doesnt add the relation from the ticket -> the differently.(This was added via the commit message)","projectPHIDs":["PHID-PROJ-358dbc2e601f7e619232","PHID-PROJ-f58a9ac58c333f106a69"],"uri":"https:\/\/secure.phabricator.com\/T722","auxiliary":[],"objectName":"T722","dateCreated":"1325553508","dateModified":"1325618490"}},"error_code":null,"error_info":null}'
1010
}
1111

12+
# Protect against local user's .arcrc interference.
13+
phabricator.ARCRC = {}
14+
1215
class PhabricatorTest(unittest.TestCase):
1316
def setUp(self):
1417
self.api = phabricator.Phabricator(username='test', certificate='test', host='http://localhost')

0 commit comments

Comments
 (0)