55 %macro mv_tokenauth(inds=mv_registerclient
58 ,client_secret=somesecret
59 ,grant_type=authorization_code
63 ,access_token_var=ACCESS_TOKEN
64 ,refresh_token_var=REFRESH_TOKEN
67 %global &access_token_var &refresh_token_var;
69 %local fref1 fref2 libref;
72 %mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password)
74 ,msg=%str(Invalid value
for grant_type: &grant_type)
77 %
if %mf_existds(&inds) %then %
do;
80 call symputx(
'client_id',client_id,
'l');
81 call symputx(
'client_secret',client_secret,
'l');
82 if not missing(auth_code) then call symputx(
'code',auth_code,
'l');
86 %mp_abort(iftrue=(&grant_type=authorization_code and %str(&code)=%str())
88 ,msg=%str(Authorization code required)
91 %mp_abort(iftrue=(&grant_type=password and (%str(&user)=%str() or %str(&pass)=%str()))
93 ,msg=%str(username / password required)
97 %let fref1=%mf_getuniquefileref();
101 if "&grant_type"=
'authorization_code' then
string=cats(
102 'grant_type=authorization_code&code=',symget(
'code'));
103 else string=cats(
'grant_type=password&username=',symget(
'user')
104 ,
'&password=',symget(pass));
105 call symputx(
'grantstring',cats(
"'",
string,
"'"));
112 %
if &base_uri=#NOTSET# %then %let base_uri=%mf_getplatform(VIYARESTAPI);
114 %let fref2=%mf_getuniquefileref();
115 proc http method=
'POST' in=&grantstring out=&fref2
116 url=
"&base_uri/SASLogon/oauth/token"
117 WEBUSERNAME=
"&client_id"
118 WEBPASSWORD=
"&client_secret"
120 headers
"Accept"=
"application/json"
121 "Content-Type"=
"application/x-www-form-urlencoded";
129 %let libref=%mf_getuniquelibref();
130 libname &libref JSON fileref=&fref2;
135 call symputx(
"&access_token_var",access_token);
136 call symputx(
"&refresh_token_var",refresh_token);
140 libname &libref clear;
141 filename &fref1 clear;
142 filename &fref2 clear;