1# Copyright 2015 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5"""Module contains a simple client lib to interact with OAuth.""" 6 7import json 8import urllib2 9 10import common 11from fake_device_server.client_lib import common_client 12from fake_device_server import oauth 13 14 15class OAuthClient(common_client.CommonClient): 16 """Client library for interacting with OAuth.""" 17 18 def __init__(self, *args, **kwargs): 19 common_client.CommonClient.__init__( 20 self, oauth.OAUTH_PATH, *args, **kwargs) 21 22 23 def invalidate_all_access_tokens(self): 24 """Invalidates all access tokens previously issued.""" 25 headers = self.add_auth_headers({'Content-Type': 'application/json'}) 26 request = urllib2.Request(self.get_url(['invalidate_all_access_tokens']), 27 json.dumps(dict()), headers=headers) 28 url_h = urllib2.urlopen(request) 29 return json.loads(url_h.read()) 30 31 32 def invalidate_all_refresh_tokens(self): 33 """Invalidates all refresh tokens previously issued.""" 34 headers = self.add_auth_headers({'Content-Type': 'application/json'}) 35 request = urllib2.Request( 36 self.get_url(['invalidate_all_refresh_tokens']), 37 json.dumps(dict()), headers=headers) 38 url_h = urllib2.urlopen(request) 39 return json.loads(url_h.read()) 40