@sasjs/core 4.10.0 → 4.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/viya/mv_registerclient.sas +64 -48
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
@file mv_registerclient.sas
|
|
3
3
|
@brief Register Client and Secret (admin task)
|
|
4
|
-
@details When building apps on SAS Viya,
|
|
5
|
-
required. In order to generate them,
|
|
6
|
-
|
|
7
|
-
Environment Manager).
|
|
4
|
+
@details When building apps on SAS Viya, a client id and secret are usually
|
|
5
|
+
required. In order to generate them, the Consul Token is required. To access
|
|
6
|
+
this token, you need to be a system administrator (it is not enough to be in
|
|
7
|
+
the SASAdministrator group in SAS Environment Manager).
|
|
8
8
|
|
|
9
9
|
If you are registering a lot of clients / secrets, you may find it more
|
|
10
10
|
convenient to use the [Viya Token Generator]
|
|
@@ -25,51 +25,56 @@
|
|
|
25
25
|
"https://raw.githubusercontent.com/sasjs/core/main/all.sas";
|
|
26
26
|
%inc mc;
|
|
27
27
|
|
|
28
|
+
%* generate random client using consul token as input parameter;
|
|
29
|
+
%mv_registerclient(consul_token=12x34sa43v2345n234lasd)
|
|
30
|
+
|
|
31
|
+
%* generate random client details with all scopes;
|
|
32
|
+
%mv_registerclient(scopes=openid *)
|
|
33
|
+
|
|
28
34
|
%* specific client with just openid scope;
|
|
29
35
|
%mv_registerclient(client_id=YourClient
|
|
30
36
|
,client_secret=YourSecret
|
|
31
37
|
,scopes=openid
|
|
32
38
|
)
|
|
33
39
|
|
|
34
|
-
%* generate random client details with all scopes;
|
|
35
|
-
%mv_registerclient(scopes=openid *)
|
|
36
|
-
|
|
37
40
|
%* generate random client with 90/180 second access/refresh token expiry;
|
|
38
41
|
%mv_registerclient(scopes=openid *
|
|
39
42
|
,access_token_validity=90
|
|
40
43
|
,refresh_token_validity=180
|
|
41
44
|
)
|
|
42
45
|
|
|
43
|
-
@param client_id= The client name. Auto generated if blank.
|
|
44
|
-
@param client_secret= Client secret. Auto generated if client is
|
|
45
|
-
|
|
46
|
-
@param
|
|
47
|
-
|
|
48
|
-
@param
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
@param
|
|
46
|
+
@param [in,out] client_id= The client name. Auto generated if blank.
|
|
47
|
+
@param [in,out] client_secret= Client secret. Auto generated if client is
|
|
48
|
+
blank.
|
|
49
|
+
@param [in] consul_token= (0) Provide the actual consul token value here if
|
|
50
|
+
using Viya 4 or above.
|
|
51
|
+
@param [in] scopes= (openid) List of space-seperated unquoted scopes
|
|
52
|
+
@param [in] grant_type= (authorization_code|refresh_token) Valid values are
|
|
53
|
+
"password" or "authorization_code" (unquoted). Pipe seperated.
|
|
54
|
+
@param [out] outds=(mv_registerclient) The dataset to contain the registered
|
|
55
|
+
client id and secret
|
|
56
|
+
@param [in] access_token_validity= (DEFAULT) The access token duration in
|
|
57
|
+
seconds. A value of DEFAULT will omit the entry (and use system default)
|
|
58
|
+
@param [in] refresh_token_validity= (DEFAULT) The duration of validity of the
|
|
54
59
|
refresh token in seconds. A value of DEFAULT will omit the entry (and use
|
|
55
60
|
system default)
|
|
56
|
-
@param
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
@param [in] client_name= (DEFAULT) An optional, human readable name for the
|
|
62
|
+
client.
|
|
63
|
+
@param [in] required_user_groups= A list of group names. If a user does not
|
|
64
|
+
belong to all the required groups, the user will not be authenticated and no
|
|
65
|
+
tokens are issued to this client for that user. If this field is not
|
|
66
|
+
specified, authentication and token issuance proceeds normally.
|
|
67
|
+
@param [in] autoapprove= During the auth step the user can choose which scope
|
|
68
|
+
to apply. Setting this to true will autoapprove all the client scopes.
|
|
69
|
+
@param [in] use_session= If true, access tokens issued to this client will be
|
|
64
70
|
associated with an HTTP session and revoked upon logout or time-out.
|
|
65
|
-
@param outjson= (_null_) A dataset containing the lines of JSON
|
|
66
|
-
Useful for debugging.
|
|
71
|
+
@param [out] outjson= (_null_) A dataset containing the lines of JSON
|
|
72
|
+
submitted. Useful for debugging.
|
|
67
73
|
|
|
68
74
|
@version VIYA V.03.04
|
|
69
75
|
@author Allan Bowe, source: https://github.com/sasjs/core
|
|
70
76
|
|
|
71
77
|
<h4> SAS Macros </h4>
|
|
72
|
-
@li mp_abort.sas
|
|
73
78
|
@li mf_getplatform.sas
|
|
74
79
|
@li mf_getuniquefileref.sas
|
|
75
80
|
@li mf_getuniquelibref.sas
|
|
@@ -81,6 +86,7 @@
|
|
|
81
86
|
|
|
82
87
|
%macro mv_registerclient(client_id=
|
|
83
88
|
,client_secret=
|
|
89
|
+
,consul_token=0
|
|
84
90
|
,client_name=DEFAULT
|
|
85
91
|
,scopes=openid
|
|
86
92
|
,grant_type=authorization_code|refresh_token
|
|
@@ -92,33 +98,40 @@
|
|
|
92
98
|
,refresh_token_validity=DEFAULT
|
|
93
99
|
,outjson=_null_
|
|
94
100
|
);
|
|
95
|
-
%local
|
|
101
|
+
%local fname1 fname2 fname3 libref access_token url tokloc;
|
|
96
102
|
|
|
97
103
|
%if client_name=DEFAULT %then %let client_name=
|
|
98
|
-
Generated by %mf_getuser() on %sysfunc(datetime(),datetime19.
|
|
104
|
+
Generated by %mf_getuser() (&sysuserid) on %sysfunc(datetime(),datetime19.
|
|
105
|
+
) using SASjs;
|
|
99
106
|
|
|
100
107
|
options noquotelenmax;
|
|
101
|
-
/* first, get consul token needed to get client id / secret */
|
|
102
|
-
%let tokloc=/etc/SASSecurityCertificateFramework/tokens/consul/default;
|
|
103
|
-
%let tokloc=%mf_loc(VIYACONFIG)&tokloc/client.token;
|
|
104
108
|
|
|
109
|
+
%if "&consul_token"="0" %then %do;
|
|
110
|
+
/* first, get consul token needed to get client id / secret */
|
|
111
|
+
%let tokloc=/etc/SASSecurityCertificateFramework/tokens/consul/default;
|
|
112
|
+
%let tokloc=%mf_loc(VIYACONFIG)&tokloc/client.token;
|
|
105
113
|
|
|
106
|
-
%
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
114
|
+
%if %sysfunc(fileexist(&tokloc))=0 %then %do;
|
|
115
|
+
%put &sysmacroname: unable to access the consul token at &tokloc;
|
|
116
|
+
%put Try passing the value in the consul= macro parameter;
|
|
117
|
+
%put See docs: https://core.sasjs.io/mv__registerclient_8sas.html;
|
|
118
|
+
%abort;
|
|
119
|
+
%end;
|
|
110
120
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
run;
|
|
121
|
+
data _null_;
|
|
122
|
+
infile "&tokloc";
|
|
123
|
+
input token:$64.;
|
|
124
|
+
call symputx('consul_token',token);
|
|
125
|
+
run;
|
|
117
126
|
|
|
118
|
-
%
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
127
|
+
%if "&consul_token"="0" %then %do;
|
|
128
|
+
%put &sysmacroname: Unable to source the consul token from &tokloc;
|
|
129
|
+
%put It seems your account (&sysuserid) does not have admin rights;
|
|
130
|
+
%put Please speak with your platform adminstrator;
|
|
131
|
+
%put Docs: https://core.sasjs.io/mv__registerclient_8sas.html;
|
|
132
|
+
%abort;
|
|
133
|
+
%end;
|
|
134
|
+
%end;
|
|
122
135
|
|
|
123
136
|
%local base_uri; /* location of rest apis */
|
|
124
137
|
%let base_uri=%mf_getplatform(VIYARESTAPI);
|
|
@@ -131,6 +144,9 @@ proc http method='POST' out=&fname1
|
|
|
131
144
|
headers "X-Consul-Token"="&consul_token";
|
|
132
145
|
run;
|
|
133
146
|
|
|
147
|
+
%put &=SYS_PROCHTTP_STATUS_CODE;
|
|
148
|
+
%put &=SYS_PROCHTTP_STATUS_PHRASE;
|
|
149
|
+
|
|
134
150
|
%let libref=%mf_getuniquelibref();
|
|
135
151
|
libname &libref JSON fileref=&fname1;
|
|
136
152
|
|