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

I am trying to follow this tutorial using proc http:

https://blogs.sas.com/content/sgf/2019/01/25/authentication-to-sas-viya/

But I am struggling with this part:

 

curl -k -X POST "https://sasserver.demo.sas.com/SASLogon/oauth/clients" \
       -H "Content-Type: application/json" \
       -H "Authorization: Bearer $IDTOKEN" \
       -d '{
        "client_id": "myclientid", 
        "client_secret": "myclientsecret",
        "scope": ["openid", "group1"],
        "authorized_grant_types": ["authorization_code","refresh_token"],
        "redirect_uri": "urn:ietf:wg:oauth:2.0:oob"
       }'

Specifically, I cant find the correct syntax for having two values in a square bracket. I am trying the following:

proc http url="&baseurl/SASLogon/oauth/clients" 
method="POST" 
auth_basic
headerout=hdrs
headerout_overwrite
in= FORM (	"client_id"="&app" 
			"client_secret"="&clientsecret"
			"scope="="['openid', 'SASapp_Admin_GUEST']"
			"authorized_grant_types"= "['authorization_code', 'refresh_token']"
        	"access_token_validity"= "350000000"
        	"redirect_uri"= "urn:ietf:wg:oauth:2.0:oob"
		
)
out=out;
headers "Content-Type"="application/json"
"Authorization"="Bearer &access_token"
;
run;

But I get  a bad request. How do I handle multiple values for scope and grant types?

1 ACCEPTED SOLUTION

Accepted Solutions
JosephHenry
SAS Employee

Ok you have a few problems here. The first and biggest one is that you are sending a Form, when the input is expected to be JSON.

You can format the JSON using a datastep, or you could simply type it in like I show below, just make sure to escape quotes with a quote.

 

The second is that you have auth_basic listed, when you are using oauth. you should use the OAUTH_BEARER option to send in the token. 

 

See the example code, I think it should work for you:

 

proc http url="httpbin.org/post" 
  method="POST" 
  headerout=hdrs
  headerout_overwrite
  in= "{""client_id"":""&app"",
 ""client_secret"":""&clientsecret"",
 ""scope="":[""openid"", ""SASapp_Admin_GUEST""],
 ""authorized_grant_types"": [""authorization_code"", ""refresh_token""],
 ""access_token_validity"": 350000000,
 ""redirect_uri"": ""urn:ietf:wg:oauth:2.0:oob""}"
  out=out
  OAUTH_BEARER="&access_token";
  headers "Content-Type"="application/json"
;
run;

View solution in original post

2 REPLIES 2
ChrisNZ
Tourmaline | Level 20

Does the query work with only one grant type?

@JosephHenry Would you mind looking?

JosephHenry
SAS Employee

Ok you have a few problems here. The first and biggest one is that you are sending a Form, when the input is expected to be JSON.

You can format the JSON using a datastep, or you could simply type it in like I show below, just make sure to escape quotes with a quote.

 

The second is that you have auth_basic listed, when you are using oauth. you should use the OAUTH_BEARER option to send in the token. 

 

See the example code, I think it should work for you:

 

proc http url="httpbin.org/post" 
  method="POST" 
  headerout=hdrs
  headerout_overwrite
  in= "{""client_id"":""&app"",
 ""client_secret"":""&clientsecret"",
 ""scope="":[""openid"", ""SASapp_Admin_GUEST""],
 ""authorized_grant_types"": [""authorization_code"", ""refresh_token""],
 ""access_token_validity"": 350000000,
 ""redirect_uri"": ""urn:ietf:wg:oauth:2.0:oob""}"
  out=out
  OAUTH_BEARER="&access_token";
  headers "Content-Type"="application/json"
;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 2 replies
  • 816 views
  • 1 like
  • 3 in conversation