59%macro mv_tokenauth(inds=mv_registerclient
62 ,client_secret=somesecret
63 ,grant_type=authorization_code
67 ,access_token_var=ACCESS_TOKEN
68 ,refresh_token_var=REFRESH_TOKEN
71%global &access_token_var &refresh_token_var;
73%local fref1 fref2 libref;
76%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password)
78 ,msg=%str(Invalid value
for grant_type: &grant_type)
81%if %mf_existds(&inds) %then %do;
84 call symputx(
'client_id',client_id,
'l');
85 call symputx(
'client_secret',client_secret,
'l');
86 if not missing(auth_code) then call symputx(
'code',auth_code,
'l');
90%mp_abort(iftrue=(&grant_type=authorization_code and %str(&code)=%str())
92 ,msg=%str(Authorization code required)
96 &grant_type=password and (%str(&user)=%str() or %str(&pass)=%str()))
98 ,msg=%str(username / password required)
102%let fref1=%mf_getuniquefileref();
106 if "&grant_type"=
'authorization_code' then
string=cats(
107 'grant_type=authorization_code&code=',symget(
'code'));
108 else string=cats(
'grant_type=password&username=',symget(
'user')
109 ,
'&password=',symget(pass));
110 call symputx(
'grantstring',cats(
"'",
string,
"'"));
117%
if &base_uri=#NOTSET# %then %let base_uri=%mf_getplatform(VIYARESTAPI);
119%let fref2=%mf_getuniquefileref();
120proc http method=
'POST' in=&grantstring out=&fref2
121 url=
"&base_uri/SASLogon/oauth/token"
122 WEBUSERNAME=
"&client_id"
123 WEBPASSWORD=
"&client_secret"
125 headers
"Accept"=
"application/json"
126 "Content-Type"=
"application/x-www-form-urlencoded";
134%let libref=%mf_getuniquelibref();
135libname &libref JSON fileref=&fref2;
140 call symputx(
"&access_token_var",access_token);
141 call symputx(
"&refresh_token_var",refresh_token);
145libname &libref clear;
146filename &fref1 clear;
147filename &fref2 clear;