コード例 #1
0
def callback():
    """
    Step 2 of OAuth2 process. This callback is requested by the HubSpot Api on the redirect response.

    The token can now be fetched using the code provided on the redirect call received.

    Once the token is persisted, the redirect for deals endpoint is returned
    """
    code = request.values.get("code")
    token = HubSpotApi.fetch_token(code=code, auth_resp_url=request.url, auth_callback_url=AUTH_REDIRECT_URL)
    try:
        Token(**token).save()
    except Exception:
        logger.exception('Error storing new token')
        abort(500)
    return redirect(url_for('.deals'))
コード例 #2
0
def test_fetch_token(mocked_token):
    token = HubSpotApi.fetch_token(code='some_code',
                                   auth_resp_url='',
                                   auth_callback_url='')
    assert token == 'a token'
コード例 #3
0
def test_fetch_token_error():
    with pytest.raises(AuthorizationError):
        HubSpotApi.fetch_token(code='some_code',
                               auth_resp_url='',
                               auth_callback_url='')