GetBearerToken2 ION API method

This ION API method obtains authentication details, including a bearer token, refresh token, token expiration time, and server URL. This method exchanges the current Ming.le session for an OAuth token when SSO is enabled, or falls back to the resource owner password flow when SSO is not available. This method includes a retry logic for error handling and returns 0 on success or 16 on failure.

Example

Parameter pattern:
  • 0 ServerID
  • 1 UseSSO
  • 2 Token
  • 3 RefreshToken
  • 4 ExpiresIn
  • 5 ServerURL
  • 6 Infobar

Return:

0 = Success, 16 = Error
public int GetBearerToken2( int serverID, bool SSO, ref string token, ref string refreshToken, ref long expiresIn, ref string serverURL, ref string infobar )
{
   string STSURL;
   string tokenURL;
   IONAPIProperties ionapi;
   try
   {
      if ( IONAPIMethodsSafe.GetIONAPIProperties( this.Context, serverID, IONAPIServers.ionapiKey, out serverURL, out STSURL, out tokenURL, out ionapi ) )
      {
         if ( !string.IsNullOrWhiteSpace( ionapi.iu ) )
           serverURL = ionapi.iu + "/" + ionapi.ti;
         else
         {
           if ( !serverURL.EndsWith( "/" ) )
              serverURL += "/";
           serverURL += IDORuntime.Context.LicenseInfo.TenantId;
         }
         (token, refreshToken, expiresIn ) = IONAPIMethodsSafe.GetBearerToken2( SSO, ionapi, STSURL, tokenURL, refreshToken );
         if ( !string.IsNullOrEmpty( token ) )
            return 0;
         else
         {
            infobar = WSStringResources.IONAPI_COULD_NOT_GET_TOKEN;;
            return 16;
         }
      }
      else
      {
         infobar = String.Format( WSStringResources.IONAPI_UNABLE_TO_RETRIEV_SERV_PROPS, serverID );
         return 16;
      }
   }
   catch ( System.Exception e )
   {
      infobar = e.Message;
      return 16;
   }
}