Hi,
I have created Third party Confidential Application in UiPath 2022 Orchestrator and i gave only user scopes .
i gave redirect url as https://oauth.pstmn.io/v1/callback while registering application and able to generate the token with postman.
how to generate the same access token with python script?
Thanks in advance.
Welcome to the community
why are you using user scope for python script?
ideally it should be application scope
cheers
Make sure you have already created your third-party confidential application in UiPath Orchestrator and have configured it with the necessary user scopes.
You’ll need the requests library to make HTTP requests.
Replace these values with your application-specific details
client_id = ‘YourClientId’
client_secret = ‘YourClientSecret’
authorization_url = ‘UiPath’
token_url = ‘https://account.uipath.com/oauth/token’
redirect_uri = ‘https://oauth.pstmn.io/v1/callback’
Use this code:
Step 1 :Get the authorization code
Step 2: Exchange the authorization code for an access token
code = ‘YourAuthorizationCode’ # Replace with the actual authorization code
data = {
‘grant_type’: ‘authorization_code’,
‘code’: code,
‘redirect_uri’: redirect_uri
}
Provide client credentials for authentication
auth = (client_id, client_secret)
response = requests.post(token_url, data=data, auth=auth)
if response.status_code == 200:
token_data = response.json()
access_token = token_data[‘access_token’]
print(f’Access Token: {access_token}‘)
else:
print(f’Error: {response.status_code} - {response.text}’)
Cheers…!
Hi Anil,
One of our client is not ready to provide application scopes. they will only give user scope.
is there any way to get the token programmatically with user scopes
Hi Dilli,
Thanks for your reply.
Can you help me how to get the Authorization code from script.
Create the authorization URL with the appropriate parameters, including the client ID, redirect URI, response type and any necessary scopes.
In a web-based application, you would typically redirect the user’s browser to the authorization URL, where they will log in and grant permissions.
you’ll need to adapt it to your specific authorization server and flow. The important part is capturing the authorization code in the callback route and using it to obtain an access token, which may involve making additional API requests to the authorization server.
Is there any way to get the access token without user input from browser.
Obtaining an access token without user input from a browser, also known as “headless” or “server-to-server” authentication, typically depends on the authentication method and the service you are interacting with. However, in many cases, you can use what’s known as the “Client Credentials” flow for OAuth 2.0 to obtain an access token programmatically without user interaction.
I have the client credentials for my Third party Application.
{
“grant_type”: “client_credentials”,
“client_id”: “{app_id}”,
“client_secret”: “{app_secret}”,
“scope”: “{scopes}”
}
with this payload when we are hitting identity/connect/token api we are not getting token .
for the same application if we give Application scope then access token is generated.
Any help here.
Thanks
If you are using the “client credentials” grant type to request an access token from a third-party identity provider, and you are not receiving a token when you specify your own custom scope, but you do get a token when using the “Application” scope.
Verify that the custom scope you are using is correctly defined and configured on the identity provider’s side. It’s possible that the scope is not set up properly, and that’s why you’re not getting a token.