How can we get the access Token for OAuth2.0 as grant type of client credentials
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2025 10:05 AM
Hi ,
I have a requirement like I created a OAuth provider as a Grant type of "Client credentials". How can we get the Access token and refresh token for every 15 minutes to make the connection active. I had referred few posts as a grant type of Resource owner password credentials.
Can some one help me how can I achieve this.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2025 08:16 PM
Have you looked into the GlideOAuthToken API?
E.g, if you have defined an OAuth 2.0 Credentials [oauth_2_0_credentials] record for an OAuth client (with a grant type of Client Credentials), you could write something like:
var oAuthClient = new sn_auth.GlideOAuthClient();
var oauth20Credentials = '<Sys ID of the OAuth 2.0 Credentials [oauth_2_0_credentials] record>';
var oauthEntityProfile = 'value of field OAuth Entity Profile [oauth_entity_profile] of the same OAuth 2.0 Credentials [oauth_2_0_credentials] record';
var token = oAuthClient.getToken(oauth20Credentials, oauthEntityProfile);
gs.debug(token.getAccessToken());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2025 09:36 PM
refer below links
OAuth2.0: Get new Access Token from existing Refresh Token
How to Setup OAuth2 authentication for outbound RESTMessageV2 integrations
OAuth : Script to Automate Token Request
How to generate the access token once it is expired from Business Rule?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader