Add an api endpoint to fetch GOOGLE_CLIENT_ID

Further to #102, this provides an endpoint suitable for mobile apps to
consume the GOOGLE_CLIENT_ID if configured.
This commit is contained in:
Darren Worrall 2015-10-02 12:23:26 +01:00 committed by Luke Faraone
parent ea65715ef8
commit 77fad7a16e
3 changed files with 28 additions and 0 deletions

View File

@ -83,6 +83,25 @@ class PublicURLTest(TestCase):
for status_code, url_set in post_urls.iteritems():
self.fetch("post", url_set, status_code)
def test_get_gcid_when_not_configured(self):
with self.settings(GOOGLE_CLIENT_ID=None):
resp = self.client.get("/api/v1/fetch_google_client_id")
self.assertEquals(400, resp.status_code,
msg="Expected 400, received %d for GET /api/v1/fetch_google_client_id" % resp.status_code,
)
data = ujson.loads(resp.content)
self.assertEqual('error', data['result'])
def test_get_gcid_when_configured(self):
with self.settings(GOOGLE_CLIENT_ID="ABCD"):
resp = self.client.get("/api/v1/fetch_google_client_id")
self.assertEquals(200, resp.status_code,
msg="Expected 200, received %d for GET /api/v1/fetch_google_client_id" % resp.status_code,
)
data = ujson.loads(resp.content)
self.assertEqual('success', data['result'])
self.assertEqual('ABCD', data['google_client_id'])
class LoginTest(AuthedTestCase):
"""
Logging in, registration, and logging out.

View File

@ -1881,6 +1881,12 @@ def json_fetch_api_key(request, user_profile, password=REQ(default='')):
return json_error("Your username or password is incorrect.")
return json_success({"api_key": user_profile.api_key})
@csrf_exempt
def api_fetch_google_client_id(request):
if not settings.GOOGLE_CLIENT_ID:
return json_error("GOOGLE_CLIENT_ID is not configured", status=400)
return json_success({"google_client_id": settings.GOOGLE_CLIENT_ID})
def get_status_list(requesting_user_profile):
return {'presences': get_status_dict(requesting_user_profile),
'server_timestamp': time.time()}

View File

@ -153,6 +153,9 @@ urlpatterns += patterns('zerver.views',
# password/pair and returns an API key.
url(r'^api/v1/fetch_api_key$', 'api_fetch_api_key'),
# Used to present the GOOGLE_CLIENT_ID to mobile apps
url(r'^api/v1/fetch_google_client_id$', 'api_fetch_google_client_id'),
# These are integration-specific web hook callbacks
url(r'^api/v1/external/beanstalk$' , 'webhooks.api_beanstalk_webhook'),
url(r'^api/v1/external/github$', 'webhooks.api_github_landing'),