<?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 In a PROC HTTP call , how to secure the client_secret and client_id in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/In-a-PROC-HTTP-call-how-to-secure-the-client-secret-and-client/m-p/893861#M43666</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;we were asked to switch from the use of an api token to a bearer token.&lt;/P&gt;
&lt;P&gt;I would like to know how to secure the client_secret and the client_id macro value in a manner that they are not visible no were , special&amp;nbsp;ly into the log file and the SAS will remember those values when the macro function BearerToken will be triggered.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Here's the content of the include statement (the values are truncated for safety purpose)

options nonotes nosource nosymbolgen;

%let client_secret=...OQ2JpllUr5xAapIH72YNUOrrVBDbs;
%let client_id=...ae890;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro function BearerToken&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%include ".../Credentials.sas";

%macro BearerToken(client_id, client_secret);
options source notes ;
/* Example of call: %BearerToken(&amp;amp;client_id., &amp;amp;client_secret.); */


/* For debugging only ! Reading the input values 
%put reading the input values: &amp;amp;=client_id &amp;amp;=client_secret;
*/

/**** Converting the Client_id and the client_secret using base64 encoder to obtain the corresponding Basic Authentication value  ***/
data _null_;
  length newString $200.;
  newString=cats("&amp;amp;client_id.",":","&amp;amp;client_secret.");
  call symputx('Basic_Auth',put(trim(newString),$base64x300.),'g');
run;

/* For debugging only !
%put &amp;amp;=Basic_Auth;
*/


/* Sending the Basic Authentication value to the appropriate web site, via an API call to obtain the Bearer_token ****/

options set=SSLREQCERT="allow";
filename resp temp;

/* must include content-type/CT= option */
proc http 
 url="https://ca1.qualtrics.com/oauth2/token"
 method='POST'
 AUTH_BASIC
 AUTH_NEGOTIATE
 ct="application/x-www-form-urlencoded"
/* in='grant_type=client_credentials&amp;amp;scope=read:survey_responses read:users'*/
 in='grant_type=client_credentials&amp;amp;scope=manage:all'
 out=resp;
 headers "Authorization" = "Basic &amp;amp;Basic_Auth."; 
;
run;
/* Checking the log for the API Call */

%put &amp;amp;=SYS_PROCHTTP_STATUS_CODE;
data _null_;
 rc=jsonpp('resp','log');
run;

/* Getting the Bearer Token */

libname auth json fileref=resp;
%global Bearertimer_start BTExpIn; 
data test;
 set auth.root;
 %let Bearertimer_start = %sysfunc(datetime());
 call symputx('BearerToken',access_token,'g');
 call symput('BTExpIn',expires_in);
 call symputx('BearerTokenValid','Yes','g');
run;

%mend BearerToken;
%BearerToken(&amp;amp;client_id., &amp;amp;client_secret.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then the ValidateBearerToken&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro validateBearerToken;
%put "The inital validity period for the Bearer Token is:  &amp;amp;=BTExpIn seconds";
Data _null_;
dur = datetime() - &amp;amp;Bearertimer_start;
BearerToken_Remaining_time=&amp;amp;BTExpIn. - dur;
put "The elapsed time is :" dur;
put "the Bearer token will remain valid for :" BearerToken_Remaining_time " seconds";
if BearerToken_Remaining_time &amp;lt; 3500 then call execute("%nrstr(%BearerToken(&amp;amp;client_id., &amp;amp;client_secret.);)");
run;
%put &amp;amp;=BearerTokenValid;
%mend validateBearerToken;
%validateBearerToken;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 12 Sep 2023 18:06:13 GMT</pubDate>
    <dc:creator>alepage</dc:creator>
    <dc:date>2023-09-12T18:06:13Z</dc:date>
    <item>
      <title>In a PROC HTTP call , how to secure the client_secret and client_id</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/In-a-PROC-HTTP-call-how-to-secure-the-client-secret-and-client/m-p/893861#M43666</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;we were asked to switch from the use of an api token to a bearer token.&lt;/P&gt;
&lt;P&gt;I would like to know how to secure the client_secret and the client_id macro value in a manner that they are not visible no were , special&amp;nbsp;ly into the log file and the SAS will remember those values when the macro function BearerToken will be triggered.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Here's the content of the include statement (the values are truncated for safety purpose)

options nonotes nosource nosymbolgen;

%let client_secret=...OQ2JpllUr5xAapIH72YNUOrrVBDbs;
%let client_id=...ae890;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro function BearerToken&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%include ".../Credentials.sas";

%macro BearerToken(client_id, client_secret);
options source notes ;
/* Example of call: %BearerToken(&amp;amp;client_id., &amp;amp;client_secret.); */


/* For debugging only ! Reading the input values 
%put reading the input values: &amp;amp;=client_id &amp;amp;=client_secret;
*/

/**** Converting the Client_id and the client_secret using base64 encoder to obtain the corresponding Basic Authentication value  ***/
data _null_;
  length newString $200.;
  newString=cats("&amp;amp;client_id.",":","&amp;amp;client_secret.");
  call symputx('Basic_Auth',put(trim(newString),$base64x300.),'g');
run;

/* For debugging only !
%put &amp;amp;=Basic_Auth;
*/


/* Sending the Basic Authentication value to the appropriate web site, via an API call to obtain the Bearer_token ****/

options set=SSLREQCERT="allow";
filename resp temp;

/* must include content-type/CT= option */
proc http 
 url="https://ca1.qualtrics.com/oauth2/token"
 method='POST'
 AUTH_BASIC
 AUTH_NEGOTIATE
 ct="application/x-www-form-urlencoded"
/* in='grant_type=client_credentials&amp;amp;scope=read:survey_responses read:users'*/
 in='grant_type=client_credentials&amp;amp;scope=manage:all'
 out=resp;
 headers "Authorization" = "Basic &amp;amp;Basic_Auth."; 
;
run;
/* Checking the log for the API Call */

%put &amp;amp;=SYS_PROCHTTP_STATUS_CODE;
data _null_;
 rc=jsonpp('resp','log');
run;

/* Getting the Bearer Token */

libname auth json fileref=resp;
%global Bearertimer_start BTExpIn; 
data test;
 set auth.root;
 %let Bearertimer_start = %sysfunc(datetime());
 call symputx('BearerToken',access_token,'g');
 call symput('BTExpIn',expires_in);
 call symputx('BearerTokenValid','Yes','g');
run;

%mend BearerToken;
%BearerToken(&amp;amp;client_id., &amp;amp;client_secret.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then the ValidateBearerToken&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro validateBearerToken;
%put "The inital validity period for the Bearer Token is:  &amp;amp;=BTExpIn seconds";
Data _null_;
dur = datetime() - &amp;amp;Bearertimer_start;
BearerToken_Remaining_time=&amp;amp;BTExpIn. - dur;
put "The elapsed time is :" dur;
put "the Bearer token will remain valid for :" BearerToken_Remaining_time " seconds";
if BearerToken_Remaining_time &amp;lt; 3500 then call execute("%nrstr(%BearerToken(&amp;amp;client_id., &amp;amp;client_secret.);)");
run;
%put &amp;amp;=BearerTokenValid;
%mend validateBearerToken;
%validateBearerToken;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2023 18:06:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/In-a-PROC-HTTP-call-how-to-secure-the-client-secret-and-client/m-p/893861#M43666</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2023-09-12T18:06:13Z</dc:date>
    </item>
  </channel>
</rss>

