示例#1
0
def test_configuration_uses_oauth2_token():
    # Given properly configured ApiClient
    result = "auth configuration"
    configuration = Configuration()
    configuration.oauth2_token = FakeOAuth2Token(result)
    # When auth_settings settings created
    auth_settings = configuration.auth_settings("OAuth2")
    # Then auth_settings correct value
    assert auth_settings is result
示例#2
0
    def __init__(
        self,
        configuration=None,
        header_name=None,
        header_value=None,
        cookie=None,
        pool_threads=None,
        oauth2_token_saver=None,
        oauth2_token_getter=None,
    ):
        if configuration is None:
            configuration = Configuration()
        self.configuration = configuration
        self.pool_threads = pool_threads

        self.rest_client = rest.RESTClientObject(configuration)
        self.default_headers = {}
        if header_name is not None:
            self.default_headers[header_name] = header_value
        self.cookie = cookie
        # Set default User-Agent.
        self.user_agent = "xero-python ({version})".format(
            version=xero_python.__version__
        )
        self._oauth2_token_saver = oauth2_token_saver
        self._oauth2_token_getter = oauth2_token_getter
示例#3
0
    client_id=app.config["CLIENT_ID"],
    client_secret=app.config["CLIENT_SECRET"],
    endpoint_url="https://api.xero.com/",
    authorization_url="https://login.xero.com/identity/connect/authorize",
    access_token_url="https://identity.xero.com/connect/token",
    refresh_token_url="https://identity.xero.com/connect/token",
    scope="offline_access openid profile email accounting.transactions "
    "accounting.reports.read accounting.journals.read accounting.settings "
    "accounting.contacts accounting.attachments assets projects",
)  # type: OAuth2Application

# configure xero-python sdk client
api_client = ApiClient(
    Configuration(
        debug=app.config["DEBUG"],
        oauth2_token=OAuth2Token(client_id=app.config["CLIENT_ID"],
                                 client_secret=app.config["CLIENT_SECRET"]),
    ),
    pool_threads=1,
)


# configure token persistence and exchange point between flask-oauthlib and xero-python
@xero.tokengetter
@api_client.oauth2_token_getter
def obtain_xero_oauth2_token():
    return session.get("token")


@xero.tokensaver
@api_client.oauth2_token_saver
示例#4
0
def api_config(xero_client_id, xero_client_secret):
    config = Configuration()
    config.oauth2_token = OAuth2Token(client_id=xero_client_id,
                                      client_secret=xero_client_secret)
    return config