ADO.NET Provider for Xero

Build 22.0.8479

カスタムクレデンシャル

Desktop Authentication with a Custom OAuth App

Follow the steps below to authenticate with the credentials for a custom OAuth app. See カスタムOAuth アプリの作成.

Get and Refresh the OAuth Access Token

After setting the following, you are ready to connect:
  • AuthScheme: Set this to OAuth, PKCE (if you configured a PKCE application) or OAuthClient (if you configured a custom application).
  • InitiateOAuth: Set this to GETANDREFRESH. You can use InitiateOAuth to avoid repeating the OAuth exchange and manually setting the OAuthAccessToken.
  • OAuthClientId: Set this to the client Id assigned when you registered your app.
  • OAuthClientSecret: OAuth and OAuthClient only. Set this to the client secret assigned when you registered your app.
  • CallbackURL: OAuth and PKCE only. Set this to the redirect URI defined when you registered your app.

When you connect the 本製品 opens the OAuth endpoint in your default browser. Log in and grant permissions to the application. The 本製品 then completes the OAuth process:

  1. Extracts the access token from the callback URL and authenticates requests.
  2. Obtains a new access token when it expires.
  3. Saves OAuth values in OAuthSettingsLocation to be persisted across connections.

Web Authentication with a Custom OAuth App

When connecting via a Web application, you need to register a custom OAuth app with Xero; see カスタムOAuth アプリの作成. You can then use the 本製品 to get and manage the OAuth token values.

This flow is only supported when AuthScheme is OAuth or PKCE. When using OAuthClient, InitiateOAuth should always be set to GETANDREFRESH so the 本製品 can manage the authentication process. OAuthClient is a server-to-server mechnaism so the 本製品 can authenticate without any user interaction.

Get an OAuth Access Token

Set the following connection properties to obtain the OAuthAccessToken:
  • AuthScheme: Set this to OAuth or PKCE if you configured a PKCE application.
  • OAuthClientId: Set this to the Client Id in your app settings.
  • OAuthClientSecret: OAuth and OAuthClient only. Set this to the client secret assigned when you registered your app.
  • Scope: You may set this to a space-separated list of Xero OAuth scopes. This is recommended if your application only uses one schema, since otherwise the 本製品 will request all available scopes.

You can then call stored procedures to complete the OAuth exchange:

  1. Call the GetOAuthAuthorizationURL stored procedure. Set the AuthMode input to WEB and set the CallbackURL input to the Redirect URI you specified in your app settings.

    The stored procedure returns the URL to the OAuth endpoint.

  2. Redirect the user to the URL, where they will log in and authorize the application. They are redirected back to the callback URL.
  3. Call the GetOAuthAccessToken stored procedure. Set the AuthMode input to WEB. Set the Verifier input to the "code" parameter in the query string of the callback URL.

When connecting with PKCE, there is an additional PKCEVerifier value that must be passed between GetOAuthAuthorizationURL and GetOAuthAccessToken. This verifier is used by Xero to ensure that the authorization code is not intercepted and used by another application.

  1. Call GetOAuthAuthorizationURL as normal.
  2. In addition to the authroization URL, the 本製品 will also output a PKCEVerifier value from the stored procedure. Save this value for later use.
  3. After the user is redirected to your callback URL, pass the saved PKCEVerifier as an input to GetOAuthAccessToken.

Refresh the OAuth Access Token

You can set InitiateOAuth to REFRESH to automatically refresh the OAuth access token when it expires, or you can call the GetOAuthAccessToken stored procedure to refresh the token manually.

Automatic Refresh

To refresh the token with InitiateOAuth, set the following on the first data connection:

  • AuthScheme: Set this to OAuth, or PKCE if you registerd a PKCE application.
  • InitiateOAuth: Set this to REFRESH. You can use InitiateOAuth to avoid repeating the OAuth exchange and manually setting the OAuthAccessToken.
  • OAuthClientId: Set this to the Client Id in your app settings.
  • OAuthClientSecret: OAuth only. Set this to the Client Secret in your app settings.
  • OAuthAccessToken: Set this to the access token returned by GetOAuthAccessToken.
  • OAuthRefreshToken: Set this to the refresh token returned by GetOAuthAccessToken.
  • OAuthSettingsLocation: Set this to the path where the 本製品 will save the OAuth values, to be persisted across connections.

On subsequent data connections, set the following:

  • AuthScheme
  • InitiateOAuth
  • OAuthClientId
  • OAuthClientSecret: OAuth only.
  • OAuthSettingsLocation

Manual Refresh

You can use the GetOAuthAccessToken stored procedure to manually refresh the OAuthAccessToken. Call the stored procedure after the ExpiresIn parameter value returned by GetOAuthAccessToken has elapsed. You need to set the following connection properties:

  • AuthScheme: Set this to OAuth, or PKCE if you registerd a PKCE application.
  • OAuthClientId: Set this to the Client Id in your app settings.
  • OAuthClientSecret: Set this to the Client Secret in your app settings.

You can then call GetOAuthAccessToken with the following parameter set:

On subsequent data connections, set the following:

  • AuthScheme
  • OAuthAccessToken

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8479