GlideOAuthClientRequest - Scoped, Global

  • Versão de lançamento: Australia
  • Atualizado 12 de mar. de 2026
  • 2 min. de leitura
  • The GlideOAuthClientRequest API provides methods for handling OAuth client requests.

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

    GlideOAuthClientRequest - getGrantType()

    Retrieves the grant type.

    Tabela 1. Parameters
    Name Type Description
    none
    Tabela 2. Returns
    Type Description
    String The grant type.

    GlideOAuthClientRequest - getHeader(String name)

    Retrieves the HTTP headers for the string you provide.

    Tabela 3. Parameters
    Name Type Description
    name String The name of the parameter.
    Tabela 4. Returns
    Type Description
    StringMap The string map with the HTTP headers.

    GlideOAuthClientRequest - getHeaders()

    Retrieves the HTTP headers.

    Tabela 5. Parameters
    Name Type Description
    none
    Tabela 6. Returns
    Type Description
    StringMap The string map with the HTTP headers.

    GlideOAuthClientRequest - getParameter(String name)

    Retrieves the parameters for the parameter name you provide.

    Tabela 7. Parameters
    Name Type Description
    name String The parameter name for which you want the parameters.
    Tabela 8. Returns
    Type Description
    String The parameters.

    GlideOAuthClientRequest - getPassword()

    Retrieves the password.

    Tabela 9. Parameters
    Name Type Description
    none
    Tabela 10. Returns
    Type Description
    String The password.

    GlideOAuthClientRequest - getRefreshToken()

    Retrieves the refresh token.

    Tabela 11. Parameters
    Name Type Description
    none
    Tabela 12. Returns
    Type Description
    String The refresh token.

    GlideOAuthClientRequest - getScope()

    Retrieves the scope.

    Tabela 13. Parameters
    Name Type Description
    none
    Tabela 14. Returns
    Type Description
    String The scope.

    GlideOAuthClientRequest - getUserName()

    Retrieves the user name.

    Tabela 15. Parameters
    Name Type Description
    none
    Tabela 16. Returns
    Type Description
    String The user name.

    GlideOAuthClientRequest - setGrantType(String grantType)

    Sets the grant type for the string you provide.

    Nota:
    You only need to set the grant type if it is not already defined in the OAuth provider profile.
    Tabela 17. Parameters
    Name Type Description
    name String The grant type.
    Tabela 18. Returns
    Type Description
    void

    GlideOAuthClientRequest - setHead(String name, String value)

    Retrieves the HTTP headers for the string you provide.

    Nota:
    setHead(String name, String value) is used in global. The scoped equivalent of this method is setHeader(String name, String value).
    Tabela 19. Parameters
    Name Type Description
    name String The name of the parameter.
    value String The value of the parameter.
    Tabela 20. Returns
    Type Description
    void

    GlideOAuthClientRequest - setParameter(String name, String value)

    Sets the parameters for the name:value pair of strings you provide.

    Tabela 21. Parameters
    Name Type Description
    name String The parameter name for which you want the parameters.
    value String The value of the parameter.
    Tabela 22. Returns
    Type Description
    void

    GlideOAuthClientRequest - setPassword(String password)

    Sets the password with the string you provide.

    Tabela 23. Parameters
    Name Type Description
    password String The user name.
    Tabela 24. Returns
    Type Description
    void

    GlideOAuthClientRequest - setRefreshToken(String refreshToken)

    Sets the refresh token with the string you provide.

    Tabela 25. Parameters
    Name Type Description
    refreshToken String The refresh token.
    Tabela 26. Returns
    Type Description
    void

    This example shows a resource owner password grant type request.

    
         var tokenRequest =new GlideOAuthClientRequest();
         tokenRequest.setGrantType("password");
         tokenRequest.setUserName("itil");
         tokenRequest.setPassword("itil");
         tokenRequest.setScope(null);
     
         var oAuthClient =new GlideOAuthClient();var tokenResponse = oAuthClient.requestToken("TestClient", tokenRequest);
         gs.log("Error:"+ tokenResponse.getErrorMessage());
     
         var token = tokenResponse.getToken();if(token){
           gs.log("AccessToken:"+ token.getAccessToken());
           gs.log("AccessTokenExpiresIn:"+ token.getExpiresIn());
           gs.log("RefreshToken:"+ token.getRefreshToken());
    

    This example shows a refresh token grant type request.

    
         var tokenRequest =new GlideOAuthClientRequest();
         tokenRequest.setGrantType("refresh_token");
         tokenRequest.setRefreshToken("N-GtdSVLkWP_Cr-TysXdmNy59ZYafu5ZzAS4YaSluXDm0kCkInEnu-hwM5SsGYSFwKJ6xauVmoaq7xJNoalXFQ");
         tokenRequest.setScope(null);
     
         var oAuthClient =new GlideOAuthClient();
         tokenResponse = oAuthClient.requestToken("TestClient", tokenRequest);
         gs.log("Error:"+ tokenResponse.getErrorMessage());
         token = tokenResponse.getToken();if( token){
            gs.log("AccessToken:"+ token.getAccessToken());
            gs.log("AccessTokenExpiresIn:"+ token.getExpiresIn());
            gs.log("AccessTokenSysID:"+ token.getAccessTokenSysID());
            gs.log("RefreshToken:"+ token.getRefreshToken());
            gs.log("RefreshTokenSysID:"+ token.getRefreshTokenSysID());

    GlideOAuthClientRequest - setScope(String scope)

    Sets the scope for the string you provide.

    Nota:
    You only need to set the scope if it is not already defined in the OAuth provider.
    Tabela 27. Parameters
    Name Type Description
    scope String The scope.
    Tabela 28. Returns
    Type Description
    void

    GlideOAuthClientRequest - setUserName(String userName)

    Sets the user name with the string you provide.

    Tabela 29. Parameters
    Name Type Description
    userName String The user name.
    Tabela 30. Returns
    Type Description
    void