<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to Submit Jobs in Viya 4 Using Client Credentials? in Developers</title>
    <link>https://communities.sas.com/t5/Developers/How-to-Submit-Jobs-in-Viya-4-Using-Client-Credentials/m-p/959075#M6603</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/472687"&gt;@David971&lt;/a&gt;. Your proposal is valid. You can mix-and-match as needed. You could use cURL to generate the access and refresh tokens. I'd recommend creating variables for those values when generated. Then you can use the value of the refresh token variable to generate a new access token through your Python code. Below are sample calls to use the refresh token to generate a new access token. Note that you'll need to replace the value of the refresh token and include the base64 encoded &lt;EM&gt;clientid:clientsecret&lt;/EM&gt; string.&lt;/P&gt;
&lt;H4&gt;Python&lt;/H4&gt;
&lt;LI-CODE lang="python"&gt;import requests

url = "https://example.demo.sas.com/SASLogon/oauth/token"

payload = "grant_type=refresh_token&amp;amp;refresh_token=&amp;lt;refresh_token value&amp;gt;"
headers = {
  'Content-Type': 'application/x-www-form-urlencoded',
  'Accept': 'application/json',
  'Authorization': 'Basic &amp;lt;base64 encoded client:secret&amp;gt;'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H4&gt;cURL&lt;/H4&gt;
&lt;LI-CODE lang="shell"&gt;curl --location 'https://example.demo.sas.com/SASLogon/oauth/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Accept: application/json' \
--header 'Authorization: Basic &amp;lt;base64 encoded client:secret&amp;gt;' \
--data 'grant_type=refresh_token&amp;amp;refresh_token=&amp;lt;refresh_token value&amp;gt;'&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 12 Feb 2025 16:47:18 GMT</pubDate>
    <dc:creator>joeFurbee</dc:creator>
    <dc:date>2025-02-12T16:47:18Z</dc:date>
    <item>
      <title>How to Submit Jobs in Viya 4 Using Client Credentials?</title>
      <link>https://communities.sas.com/t5/Developers/How-to-Submit-Jobs-in-Viya-4-Using-Client-Credentials/m-p/958510#M6591</link>
      <description>&lt;P&gt;I am trying to configure a client to run jobs in&lt;STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Viya 4.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I followed the steps in this blog:&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/sgf/2023/02/07/authentication-to-sas-viya/" target="_blank" rel="noopener noreferrer"&gt;https://blogs.sas.com/content/sgf/2023/02/07/authentication-to-sas-viya/&lt;/A&gt;&lt;BR /&gt;Here is the relevant configuration of my client:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;PRE&gt;{   
  "scope": ["uaa.none"], 
  "client_id": "newclient", 
  "authorized_grant_types": ["client_credentials"], 
  "authorities": ["SASAdministrators"], 
}&lt;/PRE&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;I successfully obtain an access token using this client. However, when I use the token to submit a job request:&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import requests

url = "http://example.com/jobExecution/jobRequests/{jobRequestId}/jobs"

payload = ""
headers = {
    "Delegate-Domain": "&amp;lt;MyAuthTokenDomain&amp;gt;",
    "Content-Type": "application/json",
    "Authorization": "Bearer  &amp;lt;ACCESS-TOKEN&amp;gt;",
    "Accept": "application/json"
}

response = requests.post(url, data=payload, headers=headers)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;I get the following error:&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;PRE&gt;{ 
  "errorCode": 0, 
  "message": "OAuth2 user authentication is required for Delegate-Domain header", 
  "details": ["path: /jobExecution/jobRequests/{jobid}/jobs"], 
  "links": [], 
  "version": 2, 
  "httpStatusCode": 401 
}&lt;/PRE&gt;&lt;BR /&gt;However, if I remove the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class=""&gt;Delegate-Domain &lt;/CODE&gt;header, the request succeeds (HTTP 201), but the job in&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Environment Manager -&amp;gt; Jobs and Flows&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;fails with:&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;PRE class=""&gt;"invalid user: 'newclient'" (error code 30081)&lt;/PRE&gt;&lt;DIV class=""&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Related to Credentials Microservice?&lt;/STRONG&gt;&lt;BR /&gt;I came across&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-Viya-Authenticating-as-a-Custom-Application/ta-p/887079" target="_blank" rel="noopener noreferrer"&gt;this blog&lt;/A&gt;, which explains how the Credentials Microservice determines identity types and manages credentials. It mentions that:&lt;/DIV&gt;&lt;UL&gt;&lt;LI&gt;Custom applications should be registered as part of a group so that credentials can be managed for them.&lt;/LI&gt;&lt;LI&gt;The default authentication domain (&lt;CODE class=""&gt;DefaultAuth&lt;/CODE&gt;) is used unless configured otherwise (&lt;CODE class=""&gt;sas.compute.domain.default&lt;/CODE&gt;).&lt;/LI&gt;&lt;/UL&gt;&lt;DIV class=""&gt;&lt;STRONG&gt;In my case:&lt;/STRONG&gt;&lt;/DIV&gt;&lt;UL&gt;&lt;LI&gt;The&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE class=""&gt;sas.compute.domain.defaultis&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;currently set to DefaultAuth, but no users have credentials associated with it.&lt;/LI&gt;&lt;LI&gt;Instead, a Token Authentication Domain has been created, which is managed by a service account.&lt;/LI&gt;&lt;LI&gt;This Token Authentication Domain is what the client includes in the Delegate-Domain header when submitting a job request.&lt;/LI&gt;&lt;LI&gt;The service account has granted the Token Authentication Domain credentials to the SASAdministrators group, which my client (newclient) is a member of.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;Questions&lt;/STRONG&gt;:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Should the request to submit the job include the Delegate-Domain header when using the client_credentials grant? If so, how can I avoid the error:"OAuth2 user authentication is required for Delegate-Domain header"&lt;/LI&gt;&lt;LI&gt;Would changing&amp;nbsp;&lt;CODE class=""&gt;sas.compute.domain.defaultis&amp;nbsp;&lt;/CODE&gt;to the Token Authentication Domain allow my client to make use of the Token Authentication Domain in order to submit jobs successfully?&lt;/LI&gt;&lt;LI&gt;If I make this change, would it grant excessive permissions to all users in the application? Is there a more secure way to configure this?&lt;/LI&gt;&lt;LI&gt;Is there a better way to associate my client with valid credentials so it can submit jobs correctly?&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Thu, 06 Feb 2025 08:29:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/How-to-Submit-Jobs-in-Viya-4-Using-Client-Credentials/m-p/958510#M6591</guid>
      <dc:creator>David971</dc:creator>
      <dc:date>2025-02-06T08:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to Submit Jobs in Viya 4 Using Client Credentials?</title>
      <link>https://communities.sas.com/t5/Developers/How-to-Submit-Jobs-in-Viya-4-Using-Client-Credentials/m-p/958592#M6592</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/472687"&gt;@David971&lt;/a&gt;. I was able to reproduce your issue with Job Execution using the token created using client credentials. I was however, able to run other API calls. Can you try a couple of the simple calls below and let me know if they succeed or not? I'm working with development to troubleshoot. Thanks!&lt;/P&gt;
&lt;PRE&gt;import requests
url = "https://example.demo.sas.com/folders/folders"
payload = {}
headers = {
  'Accept': 'application/json',
  'Authorization': 'Bearer xxxxxxx'&lt;BR /&gt;}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)&lt;/PRE&gt;
&lt;PRE&gt;import requests
url = "https://example.demo.sas.com/reports/reports"
payload = {}
headers = {
  'Accept': 'application/json',
  'Authorization': 'Bearer xxxxxx'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)&lt;/PRE&gt;
&lt;PRE&gt;import requests
url = "https://example.demo.sas.com/dataSources/providers/"
payload = {}
headers = {
  'Accept': 'application/json',
  'Authorization': 'Bearer xxxxxxx'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Feb 2025 20:49:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/How-to-Submit-Jobs-in-Viya-4-Using-Client-Credentials/m-p/958592#M6592</guid>
      <dc:creator>joeFurbee</dc:creator>
      <dc:date>2025-02-06T20:49:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to Submit Jobs in Viya 4 Using Client Credentials?</title>
      <link>https://communities.sas.com/t5/Developers/How-to-Submit-Jobs-in-Viya-4-Using-Client-Credentials/m-p/958619#M6593</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/214450"&gt;@joeFurbee&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I can confirm that all of those API calls succeeded with my client credentials.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2025 08:53:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/How-to-Submit-Jobs-in-Viya-4-Using-Client-Credentials/m-p/958619#M6593</guid>
      <dc:creator>David971</dc:creator>
      <dc:date>2025-02-07T08:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to Submit Jobs in Viya 4 Using Client Credentials?</title>
      <link>https://communities.sas.com/t5/Developers/How-to-Submit-Jobs-in-Viya-4-Using-Client-Credentials/m-p/958691#M6595</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/472687"&gt;@David971&lt;/a&gt;. I've discussed with the development team and we've determined the following:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;The job execution API will not work with a client credentials token. It is not valid to launch a compute server using a client token since the client doesn’t have any real identity as far as UID/GID to launch the server with.&amp;nbsp;As an alternative, we recommend using a token created via the authorization grant type.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let me know if you'd like assistance on creating the token using the auth code.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2025 19:32:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/How-to-Submit-Jobs-in-Viya-4-Using-Client-Credentials/m-p/958691#M6595</guid>
      <dc:creator>joeFurbee</dc:creator>
      <dc:date>2025-02-07T19:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to Submit Jobs in Viya 4 Using Client Credentials?</title>
      <link>https://communities.sas.com/t5/Developers/How-to-Submit-Jobs-in-Viya-4-Using-Client-Credentials/m-p/958812#M6597</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/214450"&gt;@joeFurbee&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I’ve been working on setting up a client using the authorization grant type.&lt;/P&gt;&lt;P&gt;While I’ve successfully made it work using cURL commands, I’m encountering an issue when implementing it in Python. Here’s my code:&lt;/P&gt;&lt;PRE&gt;import requests

url = "https://example.demo.sas.com/SASLogon/oauth/token"

payload = {
    "grant_type": "refresh_token",
    "refresh_token": "&amp;lt;my_refresh_token&amp;gt;"
}
headers = {
    "Content-Type": "application/x-www-form-urlencoded"
}
auth = (testclient, "&amp;lt;clientsecret&amp;gt;")

response = requests.post(url, data=payload, headers=headers, auth=auth)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get the error:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;401 Client Error&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;S&lt;SPAN class=""&gt;copes are&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;"uaa.user", "openid", "SASAdministrator".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;Authorities is&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;"SASAdministrator".&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;I have checked and i am using the valid clientid and clientsecret.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2025 15:25:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/How-to-Submit-Jobs-in-Viya-4-Using-Client-Credentials/m-p/958812#M6597</guid>
      <dc:creator>David971</dc:creator>
      <dc:date>2025-02-10T15:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to Submit Jobs in Viya 4 Using Client Credentials?</title>
      <link>https://communities.sas.com/t5/Developers/How-to-Submit-Jobs-in-Viya-4-Using-Client-Credentials/m-p/958858#M6599</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/472687"&gt;@David971&lt;/a&gt;&amp;nbsp;. Take a look at &lt;A href="https://github.com/sassoftware/rest-api-use-cases/tree/main/authentication/scripts" target="_self"&gt;these Jupyter notebooks&lt;/A&gt; I published on sassoftware GitHub. They will walk you through the client registration for an admins and users using the authorization code grant type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In that same repository, there are &lt;A href="https://github.com/sassoftware/rest-api-use-cases/tree/main/python/job-execution" target="_self"&gt;Python examples for Job Execution&lt;/A&gt; as well as multiple other use cases.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you'd rather run it in straight Python here's a sample of what the code would look like:&lt;/P&gt;
&lt;PRE&gt;import requests

url = "https://example.demo.sas.com/SASLogon/oauth/token"

payload = "grant_type=authorization_code&amp;amp;code=&amp;lt;generated auth code&amp;gt;"}
headers = {
      'Accept': 'application/json',
      'Content-Type': 'application/x-www-form-urlencoded',
      'Authorization': 'Basic &amp;lt;base64 encoded client:secret&amp;gt;'
}

response = requests.post(url, data=payload, headers=headers, auth=auth)&lt;/PRE&gt;
&lt;P&gt;You'll need to insert the auth code you generated as well as the base64 encoded client:secret pair.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, you can get code samples in multiple languages (including Python) from the &lt;A href="https://developer.sas.com/rest-apis/SASLogon/grantAuthorizationCode" target="_self"&gt;documentation on the developer.sas.com&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2025 13:34:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/How-to-Submit-Jobs-in-Viya-4-Using-Client-Credentials/m-p/958858#M6599</guid>
      <dc:creator>joeFurbee</dc:creator>
      <dc:date>2025-02-11T13:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to Submit Jobs in Viya 4 Using Client Credentials?</title>
      <link>https://communities.sas.com/t5/Developers/How-to-Submit-Jobs-in-Viya-4-Using-Client-Credentials/m-p/959029#M6602</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Thanks for sharing the Jupyter notebooks and Python examples! I have a quick question—do I need to get the refresh token using Python for this to work? Or can I alternatively register the client and obtain the access token and refresh token using curl commands with the authorization code, then use the refresh token in a Python script? Or does everything have to be done in Python as shown in the notebook?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2025 12:50:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/How-to-Submit-Jobs-in-Viya-4-Using-Client-Credentials/m-p/959029#M6602</guid>
      <dc:creator>David971</dc:creator>
      <dc:date>2025-02-12T12:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to Submit Jobs in Viya 4 Using Client Credentials?</title>
      <link>https://communities.sas.com/t5/Developers/How-to-Submit-Jobs-in-Viya-4-Using-Client-Credentials/m-p/959075#M6603</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/472687"&gt;@David971&lt;/a&gt;. Your proposal is valid. You can mix-and-match as needed. You could use cURL to generate the access and refresh tokens. I'd recommend creating variables for those values when generated. Then you can use the value of the refresh token variable to generate a new access token through your Python code. Below are sample calls to use the refresh token to generate a new access token. Note that you'll need to replace the value of the refresh token and include the base64 encoded &lt;EM&gt;clientid:clientsecret&lt;/EM&gt; string.&lt;/P&gt;
&lt;H4&gt;Python&lt;/H4&gt;
&lt;LI-CODE lang="python"&gt;import requests

url = "https://example.demo.sas.com/SASLogon/oauth/token"

payload = "grant_type=refresh_token&amp;amp;refresh_token=&amp;lt;refresh_token value&amp;gt;"
headers = {
  'Content-Type': 'application/x-www-form-urlencoded',
  'Accept': 'application/json',
  'Authorization': 'Basic &amp;lt;base64 encoded client:secret&amp;gt;'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H4&gt;cURL&lt;/H4&gt;
&lt;LI-CODE lang="shell"&gt;curl --location 'https://example.demo.sas.com/SASLogon/oauth/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Accept: application/json' \
--header 'Authorization: Basic &amp;lt;base64 encoded client:secret&amp;gt;' \
--data 'grant_type=refresh_token&amp;amp;refresh_token=&amp;lt;refresh_token value&amp;gt;'&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2025 16:47:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/How-to-Submit-Jobs-in-Viya-4-Using-Client-Credentials/m-p/959075#M6603</guid>
      <dc:creator>joeFurbee</dc:creator>
      <dc:date>2025-02-12T16:47:18Z</dc:date>
    </item>
  </channel>
</rss>

