Example #1
0
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())
Example #2
0
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())
Example #3
0
def test_get_token_by_code():
    res_body = {
        'access_token': 'my_access_token',
        'token_type': 'bearer',
        'expires_in': 10000,
        'refresh_token': 'my_refresh_token',
        '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("")
    client = FreeeClient(
        'my_client_id',
        'my_client_secret',
        'my_redirect_uri',
        token_fp,
    )
    auth_code = 'my_auth_code'
    client.get_token_by_code(auth_code)
    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_token',
         'token_type': 'bearer',
         'expires_in': 10000,
         'refresh_token': 'my_refresh_token',
         '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': ['authorization_code'],
        'code': [auth_code],
        'redirect_uri': ['my_redirect_uri'],
        })