Excel Add-In for REST

Build 25.0.9540

GetOAuthAccessToken のオーバーライド

There may be occasions where an API may have a login endpoint that provides an access token that expires after a certain period of time. However, what the token endpoint expects may be an input standard that deviates from OAuth 2.0, such as requiring JSON input instead of URL-encoded form-data. If you want to leverage the driver's automated refresh timing even for these integrations, then you can achieve this by overriding the GetOAuthAccessToken.rsb file and including it among the schema files in the folder specified in your Location connection setting.

Example Login

For the following example, consider an API that requires the following:

  • The login request must be in the form of a POST request.
  • An API Key must be supplied in the x-api-key header of the request.
  • The Email and Password of a user must be provided in the body of the request in JSON format.
  • The access token is returned in the token field of the response, and has an implicit lifetime of 30 minutes.

In this example, the details of the request are populated from specific connection properties via the _connection item. The URI for the request comes from the OAuthAccessTokenURL property. The value of OAuthClientId is used to populate the value of the x-api-key header here. Both User and Password are used to fill the JSON body of the request.

Any override of the GetOAuthAccessToken stored procedure must at minimum push OAuthAccessToken and ExpiresIn as outputs in order for the automated refresh to work properly. In the example below, the OAuthAccessToken output is mapped to the token field of the response in the element map. Since the expiration time is not in the response but is rather implicitly assumed, the RSB file instead sets ExpiresIn to 1800 (in seconds) explicitly in the init output item prior to pushing. Finally, the api:call keyword is configured to call jsonproviderGet instead of oauthGetAccessToken, since there is a custom tailored request that needs to be sent.

<api:script xmlns:api="http://www.rssbus.com/ns/rsbscript/2">

  <api:info title="GetOAuthAccessToken" description="Obtains the OAuth access token to be used for authentication.">
    <output name="OAuthAccessToken"    desc="The authentication token returned. This can be used in subsequent calls to other operations for this particular service."/>
    <output name="ExpiresIn"           desc="The remaining lifetime on the access token."/>
  </api:info>

  <api:set attr="login.elementmapname#" value="OAuthAccessToken" />
  <api:set attr="login.elementmappath#" value="/json/token" />

  <api:set attr="login.authscheme" value="NONE" />
  <api:set attr="login.uri" value="[_connection.OAuthAccessTokenURL]" />
  <api:set attr="login.method" value="POST" />
  <api:set attr="login.Header:Name#1" value="x-api-key" />
  <api:set attr="login.Header:Value#1" value="[_connection.OAuthClientId]" />
  
  <api:set attr="login.ContentType" value="application/json" />
  <api:set attr="login.Data">{"Email":"[_connection.User]","Password":"[_connection.Password]"}</api:set>

  <api:call op="jsonproviderGet" input="login" out="init">
    <api:set attr="init.ExpiresIn" value="1800" />
    <api:push item="init"/>
  </api:call>
  
</api:script>

Copyright (c) 2026 CData Software, Inc. - All rights reserved.
Build 25.0.9540