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?
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;
Does the query work with only one grant type?
@JosephHenry Would you mind looking?
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.