BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RichardP
Quartz | Level 8

Hello, 

 

can someone please help me convert the following (working) cURL command into the PROC HTTP equivalent?

 

curl -k http://sasviya01.race.sas.com/SASLogon/oauth/token  -H "Content-Type: application/x-www-form-urlencoded" -u "sas.cli:" -d "grant_type=password&username=geladm&password=lnxsas"

 

This is as far as I have got, however I am struggling to understand the -u switch "sas.cli:" 

 

proc http url="http://sasviya01.race.sas.com/SASLogon/oauth/token" method="GET" auth_ntlm
in="grant_type=password&username=geladm&password=lnxsas"
out=response
headerout=hdrout
headerout_overwrite;
headers "Accept"="application/json";
run;

 

any help much appreciated!

 

regards, 

 

Richard

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
joeFurbee
Community Manager

Hi @RichardP. I'm not sure where you'll be using the proc http call, but basic auth is not considered best practice from a security standpoint. To answer you question the following call worked for me (I substituted your env values in the example):

 

filename out TEMP;
filename hdrs TEMP;
proc http url="http://sasviya01.race.sas.com/SASLogon/oauth/token" 
method="POST" 
auth_basic
Webusername="sas.cli"
webpassword=""
in='grant_type=password&username=geladm&password=lnxsas'
headerout=hdrs
headerout_overwrite
out=out;
headers "Accept"="application/json";
run;

%put return code is: &SYS_PROCHTTP_STATUS_CODE.;

data _null_;
infile out;
input;
put _infile_;
run;

I ran the program in SAS Studio. The first part of the program retrieves the access token. The second part displays the result.

 

The -u in your original cURL call is for "client_id:client_secret". This is reflected in the proc http call above.

 

I hope this helps,

Joe

 

Blog post articles on authentication you may find helpful:


Join us for SAS Community Trivia
SAS Bowl XLIII, The New SAS Developer Portal
Wednesday, August 14, 2024, at 10 a.m. ET | #SASBowl

View solution in original post

5 REPLIES 5
FriedEgg
SAS Employee

-u in cURL refers to user name/password for basic authentication. In the below, "sas.cli" would be the username and whatever is after the ":" would be the password.

 

In PROC HTTP you are using AUTH_NTLM instead of basic authentication.  You would instead want to use AUTH_BASIC and WEB_USERNAME and WEB_PASSWORD options.

RichardP
Quartz | Level 8

Hi thanks for your reply. In my cURL command I have a username "geladm" and a password "lnxsas". Therefore I am confused as to where the -u switch information should go. I have tried your suggestion and a whole heap of combinations but I always get an access error. 

regards, 

 

Richard

 

joeFurbee
Community Manager

Hi @RichardP. I'm not sure where you'll be using the proc http call, but basic auth is not considered best practice from a security standpoint. To answer you question the following call worked for me (I substituted your env values in the example):

 

filename out TEMP;
filename hdrs TEMP;
proc http url="http://sasviya01.race.sas.com/SASLogon/oauth/token" 
method="POST" 
auth_basic
Webusername="sas.cli"
webpassword=""
in='grant_type=password&username=geladm&password=lnxsas'
headerout=hdrs
headerout_overwrite
out=out;
headers "Accept"="application/json";
run;

%put return code is: &SYS_PROCHTTP_STATUS_CODE.;

data _null_;
infile out;
input;
put _infile_;
run;

I ran the program in SAS Studio. The first part of the program retrieves the access token. The second part displays the result.

 

The -u in your original cURL call is for "client_id:client_secret". This is reflected in the proc http call above.

 

I hope this helps,

Joe

 

Blog post articles on authentication you may find helpful:


Join us for SAS Community Trivia
SAS Bowl XLIII, The New SAS Developer Portal
Wednesday, August 14, 2024, at 10 a.m. ET | #SASBowl

RichardP
Quartz | Level 8

Joe, 

 

thank you so much for this!! Your solution worked first time. In response to your remark, I will be creating a simple report showing the tables used in a VA report. I actually posted a question about this (and thank you for your help here as well). 

 

https://communities.sas.com/t5/Developers/Create-a-report-table-relationship-report/m-p/617481

 

I was following a paper - OpenID Connect Opens the Door to SAS® Viya® APIs. I was trying to create an access token for SAS Studio (duh!) Thanks to your help I now realise that SAS Studio is already a client and therefore gaining an access token is not needed. By adding the OAUTH_BEARER=SAS_SERVICES to the PROC HTTP statement I can take advantage of the authentication which took place with SAS Logon.  

 

many thanks!

Richard

 

carl_sommer
SAS Employee

Very helpful.  BTW, you may find it a bit easier to display the response JSON to the log using the jsonpp() function :

 

data _null_;

  rc = jsonpp('out','log');

run;

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 8202 views
  • 3 likes
  • 4 in conversation