mirror of
https://github.com/sasjs/core.git
synced 2026-01-05 08:30:06 +00:00
Compare commits
4 Commits
v4.9.4
...
allanbowe/
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f0a5d89016 | ||
|
|
07bde4b25c | ||
|
|
80b06af581 | ||
|
|
3c026811e9 |
158
all.sas
158
all.sas
@@ -11271,6 +11271,7 @@ create table &outds as
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mf_getplatform.sas
|
||||
@li mfs_httpheader.sas
|
||||
@li mp_binarycopy.sas
|
||||
|
||||
@author Allan Bowe
|
||||
@@ -11304,7 +11305,7 @@ data _null_;
|
||||
run;
|
||||
|
||||
%if &contentype=CSV %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) %then %do;
|
||||
data _null_;
|
||||
rc=stpsrv_header('Content-type','application/csv');
|
||||
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
|
||||
@@ -11315,10 +11316,14 @@ run;
|
||||
contenttype='application/csv'
|
||||
contentdisp="attachment; filename=&outname";
|
||||
%end;
|
||||
%else %if &platform=SASJS %then %do;
|
||||
%mfs_httpheader(Content-type,application/csv)
|
||||
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
|
||||
%end;
|
||||
%end;
|
||||
%else %if &contentype=EXCEL %then %do;
|
||||
/* suitable for XLS format */
|
||||
%if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) %then %do;
|
||||
data _null_;
|
||||
rc=stpsrv_header('Content-type','application/vnd.ms-excel');
|
||||
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
|
||||
@@ -11329,9 +11334,13 @@ run;
|
||||
contenttype='application/vnd.ms-excel'
|
||||
contentdisp="attachment; filename=&outname";
|
||||
%end;
|
||||
%else %if &platform=SASJS %then %do;
|
||||
%mfs_httpheader(Content-type,application/vnd.ms-excel)
|
||||
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
|
||||
%end;
|
||||
%end;
|
||||
%else %if &contentype=GIF or &contentype=JPEG or &contentype=PNG %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) %then %do;
|
||||
data _null_;
|
||||
rc=stpsrv_header('Content-type',"image/%lowcase(&contenttype)");
|
||||
run;
|
||||
@@ -11340,15 +11349,21 @@ run;
|
||||
filename &outref filesrvc parenturi="&SYS_JES_JOB_URI"
|
||||
contenttype="image/%lowcase(&contenttype)";
|
||||
%end;
|
||||
%else %if &platform=SASJS %then %do;
|
||||
%mfs_httpheader(Content-type,image/%lowcase(&contenttype))
|
||||
%end;
|
||||
%end;
|
||||
%else %if &contentype=HTML %then %do;
|
||||
%if &platform=SASVIYA %then %do;
|
||||
filename &outref filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json"
|
||||
contenttype="text/html";
|
||||
%end;
|
||||
%else %if &platform=SASJS %then %do;
|
||||
%mfs_httpheader(Content-type,text/html)
|
||||
%end;
|
||||
%end;
|
||||
%else %if &contentype=TEXT %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) %then %do;
|
||||
data _null_;
|
||||
rc=stpsrv_header('Content-type','application/text');
|
||||
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
|
||||
@@ -11359,9 +11374,13 @@ run;
|
||||
contenttype='application/text'
|
||||
contentdisp="attachment; filename=&outname";
|
||||
%end;
|
||||
%else %if &platform=SASJS %then %do;
|
||||
%mfs_httpheader(Content-type,application/text)
|
||||
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
|
||||
%end;
|
||||
%end;
|
||||
%else %if &contentype=WOFF or &contentype=WOFF2 or &contentype=TTF %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) %then %do;
|
||||
data _null_;
|
||||
rc=stpsrv_header('Content-type',"font/%lowcase(&contenttype)");
|
||||
run;
|
||||
@@ -11370,9 +11389,12 @@ run;
|
||||
filename &outref filesrvc parenturi="&SYS_JES_JOB_URI"
|
||||
contenttype="font/%lowcase(&contenttype)";
|
||||
%end;
|
||||
%else %if &platform=SASJS %then %do;
|
||||
%mfs_httpheader(Content-type,font/%lowcase(&contenttype))
|
||||
%end;
|
||||
%end;
|
||||
%else %if &contentype=XLSX %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) %then %do;
|
||||
data _null_;
|
||||
rc=stpsrv_header('Content-type',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
@@ -11385,9 +11407,15 @@ run;
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
contentdisp="attachment; filename=&outname";
|
||||
%end;
|
||||
%else %if &platform=SASJS %then %do;
|
||||
%mfs_httpheader(Content-type
|
||||
,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
|
||||
)
|
||||
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
|
||||
%end;
|
||||
%end;
|
||||
%else %if &contentype=ZIP %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) %then %do;
|
||||
data _null_;
|
||||
rc=stpsrv_header('Content-type','application/zip');
|
||||
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
|
||||
@@ -11398,6 +11426,10 @@ run;
|
||||
contenttype='application/zip'
|
||||
contentdisp="attachment; filename=&outname";
|
||||
%end;
|
||||
%else %if &platform=SASJS %then %do;
|
||||
%mfs_httpheader(Content-type,application/zip)
|
||||
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
|
||||
%end;
|
||||
%end;
|
||||
%else %do;
|
||||
%put %str(ERR)OR: Content Type &contenttype NOT SUPPORTED by &sysmacroname!;
|
||||
@@ -23104,10 +23136,10 @@ run;
|
||||
%mend mv_jobwaitfor;/**
|
||||
@file mv_registerclient.sas
|
||||
@brief Register Client and Secret (admin task)
|
||||
@details When building apps on SAS Viya, an client id and secret are sometimes
|
||||
required. In order to generate them, filesystem access to the Consul Token
|
||||
is needed (it is not enough to be in the SASAdministrator group in SAS
|
||||
Environment Manager).
|
||||
@details When building apps on SAS Viya, a client id and secret are usually
|
||||
required. In order to generate them, the Consul Token is required. To access
|
||||
this token, you need to be a system administrator (it is not enough to be in
|
||||
the SASAdministrator group in SAS Environment Manager).
|
||||
|
||||
If you are registering a lot of clients / secrets, you may find it more
|
||||
convenient to use the [Viya Token Generator]
|
||||
@@ -23128,51 +23160,56 @@ run;
|
||||
"https://raw.githubusercontent.com/sasjs/core/main/all.sas";
|
||||
%inc mc;
|
||||
|
||||
%* generate random client using consul token as input parameter;
|
||||
%mv_registerclient(consul_token=12x34sa43v2345n234lasd)
|
||||
|
||||
%* generate random client details with all scopes;
|
||||
%mv_registerclient(scopes=openid *)
|
||||
|
||||
%* specific client with just openid scope;
|
||||
%mv_registerclient(client_id=YourClient
|
||||
,client_secret=YourSecret
|
||||
,scopes=openid
|
||||
)
|
||||
|
||||
%* generate random client details with all scopes;
|
||||
%mv_registerclient(scopes=openid *)
|
||||
|
||||
%* generate random client with 90/180 second access/refresh token expiry;
|
||||
%mv_registerclient(scopes=openid *
|
||||
,access_token_validity=90
|
||||
,refresh_token_validity=180
|
||||
)
|
||||
|
||||
@param client_id= The client name. Auto generated if blank.
|
||||
@param client_secret= Client secret. Auto generated if client is blank.
|
||||
@param scopes=(openid) List of space-seperated unquoted scopes
|
||||
@param grant_type=(authorization_code|refresh_token) Valid values are
|
||||
"password" or "authorization_code" (unquoted)
|
||||
@param outds=(mv_registerclient) The dataset to contain the registered client
|
||||
id and secret
|
||||
@param access_token_validity=(DEFAULT) The duration of validity of the access
|
||||
token in seconds. A value of DEFAULT will omit the entry (and use system
|
||||
default)
|
||||
@param refresh_token_validity=(DEFAULT) The duration of validity of the
|
||||
@param [in,out] client_id= The client name. Auto generated if blank.
|
||||
@param [in,out] client_secret= Client secret. Auto generated if client is
|
||||
blank.
|
||||
@param [in] consul_token= (0) Provide the actual consul token value here if
|
||||
using Viya 4 or above.
|
||||
@param [in] scopes= (openid) List of space-seperated unquoted scopes
|
||||
@param [in] grant_type= (authorization_code|refresh_token) Valid values are
|
||||
"password" or "authorization_code" (unquoted). Pipe seperated.
|
||||
@param [out] outds=(mv_registerclient) The dataset to contain the registered
|
||||
client id and secret
|
||||
@param [in] access_token_validity= (DEFAULT) The access token duration in
|
||||
seconds. A value of DEFAULT will omit the entry (and use system default)
|
||||
@param [in] refresh_token_validity= (DEFAULT) The duration of validity of the
|
||||
refresh token in seconds. A value of DEFAULT will omit the entry (and use
|
||||
system default)
|
||||
@param name= An optional, human readable name for the client
|
||||
@param required_user_groups= A list of group names. If a user does not belong
|
||||
to all the required groups, the user will not be authenticated and no tokens
|
||||
are issued to this client for that user. If this field is not specified,
|
||||
authentication and token issuance proceeds normally.
|
||||
@param autoapprove= During the auth step the user can choose which scope to
|
||||
apply. Setting this to true will autoapprove all the client scopes.
|
||||
@param use_session= If true, access tokens issued to this client will be
|
||||
@param [in] client_name= (DEFAULT) An optional, human readable name for the
|
||||
client.
|
||||
@param [in] required_user_groups= A list of group names. If a user does not
|
||||
belong to all the required groups, the user will not be authenticated and no
|
||||
tokens are issued to this client for that user. If this field is not
|
||||
specified, authentication and token issuance proceeds normally.
|
||||
@param [in] autoapprove= During the auth step the user can choose which scope
|
||||
to apply. Setting this to true will autoapprove all the client scopes.
|
||||
@param [in] use_session= If true, access tokens issued to this client will be
|
||||
associated with an HTTP session and revoked upon logout or time-out.
|
||||
@param outjson= (_null_) A dataset containing the lines of JSON submitted.
|
||||
Useful for debugging.
|
||||
@param [out] outjson= (_null_) A dataset containing the lines of JSON
|
||||
submitted. Useful for debugging.
|
||||
|
||||
@version VIYA V.03.04
|
||||
@author Allan Bowe, source: https://github.com/sasjs/core
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mp_abort.sas
|
||||
@li mf_getplatform.sas
|
||||
@li mf_getuniquefileref.sas
|
||||
@li mf_getuniquelibref.sas
|
||||
@@ -23184,6 +23221,7 @@ run;
|
||||
|
||||
%macro mv_registerclient(client_id=
|
||||
,client_secret=
|
||||
,consul_token=0
|
||||
,client_name=DEFAULT
|
||||
,scopes=openid
|
||||
,grant_type=authorization_code|refresh_token
|
||||
@@ -23195,33 +23233,40 @@ run;
|
||||
,refresh_token_validity=DEFAULT
|
||||
,outjson=_null_
|
||||
);
|
||||
%local consul_token fname1 fname2 fname3 libref access_token url tokloc;
|
||||
%local fname1 fname2 fname3 libref access_token url tokloc;
|
||||
|
||||
%if client_name=DEFAULT %then %let client_name=
|
||||
Generated by %mf_getuser() on %sysfunc(datetime(),datetime19.) using SASjs;
|
||||
Generated by %mf_getuser() (&sysuserid) on %sysfunc(datetime(),datetime19.
|
||||
) using SASjs;
|
||||
|
||||
options noquotelenmax;
|
||||
/* first, get consul token needed to get client id / secret */
|
||||
%let tokloc=/etc/SASSecurityCertificateFramework/tokens/consul/default;
|
||||
%let tokloc=%mf_loc(VIYACONFIG)&tokloc/client.token;
|
||||
|
||||
%if "&consul_token"="0" %then %do;
|
||||
/* first, get consul token needed to get client id / secret */
|
||||
%let tokloc=/etc/SASSecurityCertificateFramework/tokens/consul/default;
|
||||
%let tokloc=%mf_loc(VIYACONFIG)&tokloc/client.token;
|
||||
|
||||
%mp_abort(iftrue=(%sysfunc(fileexist(&tokloc))=0)
|
||||
,mac=&sysmacroname
|
||||
,msg=%str(Unable to access the consul token at &tokloc)
|
||||
)
|
||||
%if %sysfunc(fileexist(&tokloc))=0 %then %do;
|
||||
%put &sysmacroname: unable to access the consul token at &tokloc;
|
||||
%put Try passing the value in the consul= macro parameter;
|
||||
%put See docs: https://core.sasjs.io/mv__registerclient_8sas.html;
|
||||
%abort;
|
||||
%end;
|
||||
|
||||
%let consul_token=0;
|
||||
data _null_;
|
||||
infile "&tokloc";
|
||||
input token:$64.;
|
||||
call symputx('consul_token',token);
|
||||
run;
|
||||
data _null_;
|
||||
infile "&tokloc";
|
||||
input token:$64.;
|
||||
call symputx('consul_token',token);
|
||||
run;
|
||||
|
||||
%mp_abort(iftrue=("&consul_token"="0")
|
||||
,mac=&sysmacroname
|
||||
,msg=%str(Unable to source the consul token from &tokloc)
|
||||
)
|
||||
%if "&consul_token"="0" %then %do;
|
||||
%put &sysmacroname: Unable to source the consul token from &tokloc;
|
||||
%put It seems your account (&sysuserid) does not have admin rights;
|
||||
%put Please speak with your platform adminstrator;
|
||||
%put Docs: https://core.sasjs.io/mv__registerclient_8sas.html;
|
||||
%abort;
|
||||
%end;
|
||||
%end;
|
||||
|
||||
%local base_uri; /* location of rest apis */
|
||||
%let base_uri=%mf_getplatform(VIYARESTAPI);
|
||||
@@ -23234,6 +23279,9 @@ proc http method='POST' out=&fname1
|
||||
headers "X-Consul-Token"="&consul_token";
|
||||
run;
|
||||
|
||||
%put &=SYS_PROCHTTP_STATUS_CODE;
|
||||
%put &=SYS_PROCHTTP_STATUS_PHRASE;
|
||||
|
||||
%let libref=%mf_getuniquelibref();
|
||||
libname &libref JSON fileref=&fname1;
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mf_getplatform.sas
|
||||
@li mfs_httpheader.sas
|
||||
@li mp_binarycopy.sas
|
||||
|
||||
@author Allan Bowe
|
||||
@@ -55,7 +56,7 @@ data _null_;
|
||||
run;
|
||||
|
||||
%if &contentype=CSV %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) %then %do;
|
||||
data _null_;
|
||||
rc=stpsrv_header('Content-type','application/csv');
|
||||
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
|
||||
@@ -66,10 +67,14 @@ run;
|
||||
contenttype='application/csv'
|
||||
contentdisp="attachment; filename=&outname";
|
||||
%end;
|
||||
%else %if &platform=SASJS %then %do;
|
||||
%mfs_httpheader(Content-type,application/csv)
|
||||
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
|
||||
%end;
|
||||
%end;
|
||||
%else %if &contentype=EXCEL %then %do;
|
||||
/* suitable for XLS format */
|
||||
%if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) %then %do;
|
||||
data _null_;
|
||||
rc=stpsrv_header('Content-type','application/vnd.ms-excel');
|
||||
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
|
||||
@@ -80,9 +85,13 @@ run;
|
||||
contenttype='application/vnd.ms-excel'
|
||||
contentdisp="attachment; filename=&outname";
|
||||
%end;
|
||||
%else %if &platform=SASJS %then %do;
|
||||
%mfs_httpheader(Content-type,application/vnd.ms-excel)
|
||||
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
|
||||
%end;
|
||||
%end;
|
||||
%else %if &contentype=GIF or &contentype=JPEG or &contentype=PNG %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) %then %do;
|
||||
data _null_;
|
||||
rc=stpsrv_header('Content-type',"image/%lowcase(&contenttype)");
|
||||
run;
|
||||
@@ -91,15 +100,21 @@ run;
|
||||
filename &outref filesrvc parenturi="&SYS_JES_JOB_URI"
|
||||
contenttype="image/%lowcase(&contenttype)";
|
||||
%end;
|
||||
%else %if &platform=SASJS %then %do;
|
||||
%mfs_httpheader(Content-type,image/%lowcase(&contenttype))
|
||||
%end;
|
||||
%end;
|
||||
%else %if &contentype=HTML %then %do;
|
||||
%if &platform=SASVIYA %then %do;
|
||||
filename &outref filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json"
|
||||
contenttype="text/html";
|
||||
%end;
|
||||
%else %if &platform=SASJS %then %do;
|
||||
%mfs_httpheader(Content-type,text/html)
|
||||
%end;
|
||||
%end;
|
||||
%else %if &contentype=TEXT %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) %then %do;
|
||||
data _null_;
|
||||
rc=stpsrv_header('Content-type','application/text');
|
||||
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
|
||||
@@ -110,9 +125,13 @@ run;
|
||||
contenttype='application/text'
|
||||
contentdisp="attachment; filename=&outname";
|
||||
%end;
|
||||
%else %if &platform=SASJS %then %do;
|
||||
%mfs_httpheader(Content-type,application/text)
|
||||
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
|
||||
%end;
|
||||
%end;
|
||||
%else %if &contentype=WOFF or &contentype=WOFF2 or &contentype=TTF %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) %then %do;
|
||||
data _null_;
|
||||
rc=stpsrv_header('Content-type',"font/%lowcase(&contenttype)");
|
||||
run;
|
||||
@@ -121,9 +140,12 @@ run;
|
||||
filename &outref filesrvc parenturi="&SYS_JES_JOB_URI"
|
||||
contenttype="font/%lowcase(&contenttype)";
|
||||
%end;
|
||||
%else %if &platform=SASJS %then %do;
|
||||
%mfs_httpheader(Content-type,font/%lowcase(&contenttype))
|
||||
%end;
|
||||
%end;
|
||||
%else %if &contentype=XLSX %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) %then %do;
|
||||
data _null_;
|
||||
rc=stpsrv_header('Content-type',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
@@ -136,9 +158,15 @@ run;
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
contentdisp="attachment; filename=&outname";
|
||||
%end;
|
||||
%else %if &platform=SASJS %then %do;
|
||||
%mfs_httpheader(Content-type
|
||||
,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
|
||||
)
|
||||
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
|
||||
%end;
|
||||
%end;
|
||||
%else %if &contentype=ZIP %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) or &platform=SASJS %then %do;
|
||||
%if (&platform=SASMETA and &streamweb=1) %then %do;
|
||||
data _null_;
|
||||
rc=stpsrv_header('Content-type','application/zip');
|
||||
rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
|
||||
@@ -149,6 +177,10 @@ run;
|
||||
contenttype='application/zip'
|
||||
contentdisp="attachment; filename=&outname";
|
||||
%end;
|
||||
%else %if &platform=SASJS %then %do;
|
||||
%mfs_httpheader(Content-type,application/zip)
|
||||
%mfs_httpheader(Content-disposition,%str(attachment; filename=&outname))
|
||||
%end;
|
||||
%end;
|
||||
%else %do;
|
||||
%put %str(ERR)OR: Content Type &contenttype NOT SUPPORTED by &sysmacroname!;
|
||||
|
||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -7,7 +7,7 @@
|
||||
"name": "@sasjs/core",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@sasjs/cli": "3.6.0",
|
||||
"@sasjs/cli": "^3.6.0",
|
||||
"@sasjs/core": "4.4.7"
|
||||
}
|
||||
},
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
"prepare": "git rev-parse --git-dir && git config core.hooksPath ./.git-hooks || true"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sasjs/cli": "3.6.0",
|
||||
"@sasjs/cli": "^3.6.0",
|
||||
"@sasjs/core": "4.4.7"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/**
|
||||
@file mv_registerclient.sas
|
||||
@brief Register Client and Secret (admin task)
|
||||
@details When building apps on SAS Viya, an client id and secret are sometimes
|
||||
required. In order to generate them, filesystem access to the Consul Token
|
||||
is needed (it is not enough to be in the SASAdministrator group in SAS
|
||||
Environment Manager).
|
||||
@details When building apps on SAS Viya, a client id and secret are usually
|
||||
required. In order to generate them, the Consul Token is required. To access
|
||||
this token, you need to be a system administrator (it is not enough to be in
|
||||
the SASAdministrator group in SAS Environment Manager).
|
||||
|
||||
If you are registering a lot of clients / secrets, you may find it more
|
||||
convenient to use the [Viya Token Generator]
|
||||
@@ -25,51 +25,56 @@
|
||||
"https://raw.githubusercontent.com/sasjs/core/main/all.sas";
|
||||
%inc mc;
|
||||
|
||||
%* generate random client using consul token as input parameter;
|
||||
%mv_registerclient(consul_token=12x34sa43v2345n234lasd)
|
||||
|
||||
%* generate random client details with all scopes;
|
||||
%mv_registerclient(scopes=openid *)
|
||||
|
||||
%* specific client with just openid scope;
|
||||
%mv_registerclient(client_id=YourClient
|
||||
,client_secret=YourSecret
|
||||
,scopes=openid
|
||||
)
|
||||
|
||||
%* generate random client details with all scopes;
|
||||
%mv_registerclient(scopes=openid *)
|
||||
|
||||
%* generate random client with 90/180 second access/refresh token expiry;
|
||||
%mv_registerclient(scopes=openid *
|
||||
,access_token_validity=90
|
||||
,refresh_token_validity=180
|
||||
)
|
||||
|
||||
@param client_id= The client name. Auto generated if blank.
|
||||
@param client_secret= Client secret. Auto generated if client is blank.
|
||||
@param scopes=(openid) List of space-seperated unquoted scopes
|
||||
@param grant_type=(authorization_code|refresh_token) Valid values are
|
||||
"password" or "authorization_code" (unquoted)
|
||||
@param outds=(mv_registerclient) The dataset to contain the registered client
|
||||
id and secret
|
||||
@param access_token_validity=(DEFAULT) The duration of validity of the access
|
||||
token in seconds. A value of DEFAULT will omit the entry (and use system
|
||||
default)
|
||||
@param refresh_token_validity=(DEFAULT) The duration of validity of the
|
||||
@param [in,out] client_id= The client name. Auto generated if blank.
|
||||
@param [in,out] client_secret= Client secret. Auto generated if client is
|
||||
blank.
|
||||
@param [in] consul_token= (0) Provide the actual consul token value here if
|
||||
using Viya 4 or above.
|
||||
@param [in] scopes= (openid) List of space-seperated unquoted scopes
|
||||
@param [in] grant_type= (authorization_code|refresh_token) Valid values are
|
||||
"password" or "authorization_code" (unquoted). Pipe seperated.
|
||||
@param [out] outds=(mv_registerclient) The dataset to contain the registered
|
||||
client id and secret
|
||||
@param [in] access_token_validity= (DEFAULT) The access token duration in
|
||||
seconds. A value of DEFAULT will omit the entry (and use system default)
|
||||
@param [in] refresh_token_validity= (DEFAULT) The duration of validity of the
|
||||
refresh token in seconds. A value of DEFAULT will omit the entry (and use
|
||||
system default)
|
||||
@param name= An optional, human readable name for the client
|
||||
@param required_user_groups= A list of group names. If a user does not belong
|
||||
to all the required groups, the user will not be authenticated and no tokens
|
||||
are issued to this client for that user. If this field is not specified,
|
||||
authentication and token issuance proceeds normally.
|
||||
@param autoapprove= During the auth step the user can choose which scope to
|
||||
apply. Setting this to true will autoapprove all the client scopes.
|
||||
@param use_session= If true, access tokens issued to this client will be
|
||||
@param [in] client_name= (DEFAULT) An optional, human readable name for the
|
||||
client.
|
||||
@param [in] required_user_groups= A list of group names. If a user does not
|
||||
belong to all the required groups, the user will not be authenticated and no
|
||||
tokens are issued to this client for that user. If this field is not
|
||||
specified, authentication and token issuance proceeds normally.
|
||||
@param [in] autoapprove= During the auth step the user can choose which scope
|
||||
to apply. Setting this to true will autoapprove all the client scopes.
|
||||
@param [in] use_session= If true, access tokens issued to this client will be
|
||||
associated with an HTTP session and revoked upon logout or time-out.
|
||||
@param outjson= (_null_) A dataset containing the lines of JSON submitted.
|
||||
Useful for debugging.
|
||||
@param [out] outjson= (_null_) A dataset containing the lines of JSON
|
||||
submitted. Useful for debugging.
|
||||
|
||||
@version VIYA V.03.04
|
||||
@author Allan Bowe, source: https://github.com/sasjs/core
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mp_abort.sas
|
||||
@li mf_getplatform.sas
|
||||
@li mf_getuniquefileref.sas
|
||||
@li mf_getuniquelibref.sas
|
||||
@@ -81,6 +86,7 @@
|
||||
|
||||
%macro mv_registerclient(client_id=
|
||||
,client_secret=
|
||||
,consul_token=0
|
||||
,client_name=DEFAULT
|
||||
,scopes=openid
|
||||
,grant_type=authorization_code|refresh_token
|
||||
@@ -92,33 +98,40 @@
|
||||
,refresh_token_validity=DEFAULT
|
||||
,outjson=_null_
|
||||
);
|
||||
%local consul_token fname1 fname2 fname3 libref access_token url tokloc;
|
||||
%local fname1 fname2 fname3 libref access_token url tokloc;
|
||||
|
||||
%if client_name=DEFAULT %then %let client_name=
|
||||
Generated by %mf_getuser() on %sysfunc(datetime(),datetime19.) using SASjs;
|
||||
Generated by %mf_getuser() (&sysuserid) on %sysfunc(datetime(),datetime19.
|
||||
) using SASjs;
|
||||
|
||||
options noquotelenmax;
|
||||
/* first, get consul token needed to get client id / secret */
|
||||
%let tokloc=/etc/SASSecurityCertificateFramework/tokens/consul/default;
|
||||
%let tokloc=%mf_loc(VIYACONFIG)&tokloc/client.token;
|
||||
|
||||
%if "&consul_token"="0" %then %do;
|
||||
/* first, get consul token needed to get client id / secret */
|
||||
%let tokloc=/etc/SASSecurityCertificateFramework/tokens/consul/default;
|
||||
%let tokloc=%mf_loc(VIYACONFIG)&tokloc/client.token;
|
||||
|
||||
%mp_abort(iftrue=(%sysfunc(fileexist(&tokloc))=0)
|
||||
,mac=&sysmacroname
|
||||
,msg=%str(Unable to access the consul token at &tokloc)
|
||||
)
|
||||
%if %sysfunc(fileexist(&tokloc))=0 %then %do;
|
||||
%put &sysmacroname: unable to access the consul token at &tokloc;
|
||||
%put Try passing the value in the consul= macro parameter;
|
||||
%put See docs: https://core.sasjs.io/mv__registerclient_8sas.html;
|
||||
%abort;
|
||||
%end;
|
||||
|
||||
%let consul_token=0;
|
||||
data _null_;
|
||||
infile "&tokloc";
|
||||
input token:$64.;
|
||||
call symputx('consul_token',token);
|
||||
run;
|
||||
data _null_;
|
||||
infile "&tokloc";
|
||||
input token:$64.;
|
||||
call symputx('consul_token',token);
|
||||
run;
|
||||
|
||||
%mp_abort(iftrue=("&consul_token"="0")
|
||||
,mac=&sysmacroname
|
||||
,msg=%str(Unable to source the consul token from &tokloc)
|
||||
)
|
||||
%if "&consul_token"="0" %then %do;
|
||||
%put &sysmacroname: Unable to source the consul token from &tokloc;
|
||||
%put It seems your account (&sysuserid) does not have admin rights;
|
||||
%put Please speak with your platform adminstrator;
|
||||
%put Docs: https://core.sasjs.io/mv__registerclient_8sas.html;
|
||||
%abort;
|
||||
%end;
|
||||
%end;
|
||||
|
||||
%local base_uri; /* location of rest apis */
|
||||
%let base_uri=%mf_getplatform(VIYARESTAPI);
|
||||
@@ -131,6 +144,9 @@ proc http method='POST' out=&fname1
|
||||
headers "X-Consul-Token"="&consul_token";
|
||||
run;
|
||||
|
||||
%put &=SYS_PROCHTTP_STATUS_CODE;
|
||||
%put &=SYS_PROCHTTP_STATUS_PHRASE;
|
||||
|
||||
%let libref=%mf_getuniquelibref();
|
||||
libname &libref JSON fileref=&fname1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user