def main(): client = FreeeClient( os.environ['OAUTH2_FREEE_CLIENT_ID'], os.environ['OAUTH2_FREEE_CLIENT_SECRET'], os.environ['OAUTH2_FREEE_REDIRECT_URI'], ) if (len(sys.argv) > 1): client.get_token_by_code(sys.argv[1]) try: print(client.me) except Exception as e: print(e) print(client.get_code_url())
def main(): client = FreeeClient( os.environ['OAUTH2_FREEE_CLIENT_ID'], os.environ['OAUTH2_FREEE_CLIENT_SECRET'], os.environ['OAUTH2_FREEE_REDIRECT_URI'], ) if(len(sys.argv)>1): client.get_token_by_code(sys.argv[1]) try: print(client.me) except Exception as e: print(e) print(client.get_code_url())
def test_access_token_not_set(): client = FreeeClient( 'my_client_id', 'my_client_secret', 'my_redirect_uri', io.StringIO("") ) res = client.me
def test_fresh_token(): res_body = { 'access_token': 'my_access_token2', 'token_type': 'bearer', 'expires_in': 10000, 'refresh_token': 'my_refresh_token2', 'scope': 'read write' } responses.add(responses.POST, "https://secure.freee.co.jp/oauth/token", status=200, body = json.dumps(res_body), content_type="application/json") token_fp = io.StringIO("{\"access_token\": \"my_access_token\"," "\"token_type\": \"my_token_type\"," "\"refresh_token\": \"my_refresh_token\"}") client = FreeeClient( 'my_client_id', 'my_client_secret', 'my_redirect_uri', token_fp, ) client.token_refresh() for attr in ('access_token', 'token_type', 'refresh_token'): eq_(res_body[attr], getattr(client, attr)) token_fp.seek(0) eq_(json.load(token_fp), {'access_token': 'my_access_token2', 'token_type': 'bearer', 'expires_in': 10000, 'refresh_token': 'my_refresh_token2', 'scope': 'read write'}) eq_(len(responses.calls), 1) req_body = urlparse.parse_qs(responses.calls[0].request.body) eq_(req_body, { 'client_id': ['my_client_id'], 'client_secret': ['my_client_secret'], 'grant_type': ['refresh_token'], 'refresh_token': ['my_refresh_token'], })
def test_get_url(): client = FreeeClient( 'my_client_id', 'my_client_secret', 'my_redirect_uri', ) eq_(client.get_code_url(), "https://secure.freee.co.jp/oauth/authorize?" + "client_id={}&redirect_uri={}&response_type=code".format( 'my_client_id', 'my_redirect_uri', )) eq_(client.get_token_url(), "https://secure.freee.co.jp/oauth/authorize?" + "client_id={}&redirect_uri={}&response_type=token".format( 'my_client_id', 'my_redirect_uri', ))
def _create_client(): token_fp = io.StringIO("{\"access_token\": \"my_access_token\"," "\"token_type\": \"my_token_type\"," "\"refresh_token\": \"my_refresh_token\"}") client = FreeeClient( 'my_client_id', 'my_client_secret', 'my_redirect_uri', token_fp, ) return client