GlideOAuthClient - Scoped, Global

  • リリースバージョン: Australia
  • 更新日 2026年03月12日
  • 所要時間:5分
  • The GlideOAuthClient API provides methods for requesting and revoking OAuth refresh and access tokens.

    You can use this API in global and scoped scripts. In scoped scripts use the sn_auth namespace identifier.

    GlideOAuthClient - getToken(String requestID, String oauthProfileID)

    Retrieves the access and refresh tokens for the client.

    表 : 1. Parameters
    Name Type Description
    requestID String Request ID from the OAuth Requestor Profile [oauth_requestor_profile] table, which references the OAuth Entity Profile [oauth_entity_profile] table.
    oauthProfileID String OAuth profile ID from the OAuth Entity Profile [oauth_entity_profile] table.
    表 : 2. Returns
    Type Description
    GlideOAuthToken The access and refresh tokens for the client.

    This example code shows how to retrieve access and refresh tokens from the instance database.

    function dumpToken(token) {
      if(token) {
         gs.info("AccessToken:" + token.getAccessToken());
         gs.info("AccessTokenExpiresIn:" + token.getExpiresIn());
         gs.info("RefreshToken:" + token.getRefreshToken());
      }
    }
    
    var oAuthClient = new  sn_auth.GlideOAuthClient();
    var token = oAuthClient.getToken('248e3017c302301089a7dd5c2840dda5', '9c4e78d3c302301089a7dd5c2840dd76');
    dumpToken(token);

    Output:

    *** Script: AccessToken:6MRxD3TRYYvIaoKr-JCy3KiaOxBPu4C9k8oafo3MYf9q8zDyHQr8UzMSM3Md2alfaES1rzSYe5ydqgbOwpm7TA
    *** Script: AccessTokenExpiresIn:1207
    *** Script: RefreshToken:sc0iTK-0PcVkRi14HXPM3vT0FyOPO8iCqC10huQoDSSLBGUSnmEv_fUfJzGWCWBb_StsXIOz6r8qF-hRhURWTA

    GlideOAuthClient - requestToken(String clientName, String jsonString)

    Retrieves the token for the client, with the request parameters encoded in JSON format.

    表 : 3. Parameters
    Name Type Description
    clientName String The client name.
    jsonString String The JSON string for the client.
    表 : 4. Returns
    Type Description
    GlideOAuthClientResponse The token for the client.

    This example shows a resource owner password grant type request, with request parameters encoded in JSON format.

    
    var oAuthClient = new GlideOAuthClient();
    var params ={grant_type:"password", username:"itil", password:'itil'};
    var json =new JSON();
    var text = json.encode(params);
    var tokenResponse = oAuthClient.requestToken('TestClient', text);
    var token = tokenResponse.getToken();
    
    gs.log("AccessToken:"+ token.getAccessToken());
    gs.log("AccessTokenExpiresIn:"+ token.getExpiresIn());
    gs.log(" RefreshToken:"+ token.getRefreshToken());
    

    GlideOAuthClient - requestTokenByRequest(String clientName, GlideOAuthClientRequest request)

    Retrieves the token for the client, with the client name and the request set into a GlideOAuthClientResponse object.

    表 : 5. Parameters
    Name Type Description
    clientName String The client name.
    request GlideOAuthClientRequest The request.
    表 : 6. Returns
    Type Description
    GlideOAuthClientResponse The token for the client.

    GlideOAuthClient - revokeToken(String clientName, String accessToken, String refreshToken, GlideOAuthClientRequest request)

    Revokes the access or refresh token for the client, with the request and optional header parameters set into a GlideOAuthClientRequest object.

    表 : 7. Parameters
    Name Type Description
    clientName String The client name.
    accessToken String The access token.
    refreshToken String The refresh token.
    request GlideOAuthClientRequest The request.
    表 : 8. Returns
    Type Description
    GlideOAuthClientResponse The token for the client.