---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# GlideOAuthClient - Scoped, Global

# GlideOAuthClient - Scoped, Global {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 1 minute to read

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) {#ariaid-title2}

Retrieves the access and refresh tokens for the client.
{#r_GlideOAuthClientRequestgetToken__table_qc4_bzf_cr__entry__3}

| 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. |
[Table 1. Parameters]

{#r_GlideOAuthClientRequestgetToken__table_qc4_bzf_cr} {#r_GlideOAuthClientRequestgetToken__table_rc4_bzf_cr__entry__2}

| Type | Description |
|-|-|
| GlideOAuthToken | The access and refresh tokens for the client. |
[Table 2. Returns]

{#r_GlideOAuthClientRequestgetToken__table_rc4_bzf_cr}  
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) {#ariaid-title3}

Retrieves the token for the client, with the request parameters encoded in JSON
format.
{#r_GlideOAuthClientRequestTokenJSON__table_qc4_bzf_cr__entry__3}

| Name | Type | Description |
|-|-|-|
| clientName | String | The client name. |
| jsonString | String | The JSON string for the client. |
[Table 3. Parameters]

{#r_GlideOAuthClientRequestTokenJSON__table_qc4_bzf_cr} {#r_GlideOAuthClientRequestTokenJSON__table_rc4_bzf_cr__entry__2}

| Type | Description |
|-|-|
| GlideOAuthClientResponse | The token for the client. |
[Table 4. Returns]

{#r_GlideOAuthClientRequestTokenJSON__table_rc4_bzf_cr}  
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) {#ariaid-title4}

Retrieves the token for the client, with the client name and the request set into a
GlideOAuthClientResponse object.
{#r_GOAC-RequestTokenByRequest__table_qc4_bzf_cr__entry__3}

| Name | Type | Description |
|-|-|-|
| clientName | String | The client name. |
| request | GlideOAuthClientRequest | The request. |
[Table 5. Parameters]

{#r_GOAC-RequestTokenByRequest__table_qc4_bzf_cr} {#r_GOAC-RequestTokenByRequest__table_rc4_bzf_cr__entry__2}

| Type | Description |
|-|-|
| GlideOAuthClientResponse | The token for the client. |
[Table 6. Returns]

{#r_GOAC-RequestTokenByRequest__table_rc4_bzf_cr}

## GlideOAuthClient - revokeToken(String clientName, String accessToken, String refreshToken,
GlideOAuthClientRequest request) {#ariaid-title5}

Revokes the access or refresh token for the client, with the request and optional
header parameters set into a GlideOAuthClientRequest object.
{#r_GOAC-RevokeTokenClientRequest__table_qc4_bzf_cr__entry__3}

| Name | Type | Description |
|-|-|-|
| clientName | String | The client name. |
| accessToken | String | The access token. |
| refreshToken | String | The refresh token. |
| request | GlideOAuthClientRequest | The request. |
[Table 7. Parameters]

{#r_GOAC-RevokeTokenClientRequest__table_qc4_bzf_cr} {#r_GOAC-RevokeTokenClientRequest__table_rc4_bzf_cr__entry__2}

| Type | Description |
|-|-|
| GlideOAuthClientResponse | The token for the client. |
[Table 8. Returns]

{#r_GOAC-RevokeTokenClientRequest__table_rc4_bzf_cr}

