- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2022 08:41 PM
I have a successfully working Outbound REST Message configured with an OAuth2 Application Registered. This is a normal Azure AD OAuth Application, and i am using Authorization Code flow.. This has all been done using the UI. I can click (manually) Get OAuth Token and get an OAuth token. I can then write a Widget with var r = new sn_ws.RESTMessageV2('OAuthAppName', 'MethodName');
This all works wonderfully well etc, my Widgets all work, i can call the API and pull the data back into ServiceNow.
After an hour, my token expires and my Widgets stop working. This is expected, however, I had assumed that calling sn_ws.RESTMessageV2()
in my Widget server side code would automatically handle all of the authentication again, instead of an administrator manually clicking on "Get OAuth Token" again.
I feel like i have read every possible blog/forum article addressing this issue, but unfortunately, I haven't been able to work out how to re-authenticate whenever someone uses my widget.
Do i really have to write my own oauthclient() code to request authorization and exchange that for a token, when that functionality is already written and hidden behind that "Get OAuth Token" button.
How do i automate this please?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2022 08:54 PM
Please refer to the link below where your issue is already addressed
https://community.servicenow.com/community?id=community_question&sys_id=5b544769dbd8dbc01dcaf3231f961937
Thanks & Regards,
Vasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2022 08:54 PM
Please refer to the link below where your issue is already addressed
https://community.servicenow.com/community?id=community_question&sys_id=5b544769dbd8dbc01dcaf3231f961937
Thanks & Regards,
Vasanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2022 11:59 AM
For completeness, what i had to do to resolve this issue was add the openid and offline_access scopes to my oath profile. Without theses scopes, i didn't have a refresh token, and so of course, there was nothing to "refresh" with.
Once the offline_access scope was added, the app registration+RestMessage services handle the refreshing automatically, and i don't have to do anything in code/script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 05:21 AM
Hi @Andrew81
Can you please share where and how you added openid and offline_access scopes?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-14-2025 02:10 AM
can you guide use how you did that?