File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < iostream>
2+
3+ #include " scitokens.h"
4+
5+ int main (int argc, const char ** argv) {
6+ if (argc < 6 ) {
7+ std::cerr << " Usage: " << argv[0 ] << " (TOKEN) (ISSUER) (AUDIENCE) (AUTHZ) (PATH)" << std::endl;
8+ return 1 ;
9+ }
10+ std::string token (argv[1 ]);
11+ std::string issuer (argv[2 ]);
12+ std::string audience (argv[3 ]);
13+ std::string authz (argv[4 ]);
14+ std::string path (argv[5 ]);
15+
16+ const char *aud_list[2 ];
17+ aud_list[0 ] = audience.c_str ();
18+ aud_list[1 ] = nullptr ;
19+
20+ SciToken scitoken;
21+ char *err_msg = nullptr ;
22+ if (scitoken_deserialize (token.c_str (), &scitoken, nullptr , &err_msg)) {
23+ std::cout << " Failed to deserialize a token: " << err_msg << std::endl;
24+ return 1 ;
25+ }
26+ std::cout << " Token deserialization successful. Checking authorizations." << std::endl;
27+ Enforcer enf;
28+ if (!(enf = enforcer_create (issuer.c_str (), aud_list, &err_msg))) {
29+ std::cout << " Failed to create a new enforcer object: " << err_msg << std::endl;
30+ return 1 ;
31+ }
32+ const Acl acl {authz.c_str (), path.c_str ()};
33+ if (enforcer_test (enf, scitoken, &acl, &err_msg)) {
34+ if (err_msg) {std::cout << " Access test failed: " << err_msg << std::endl;}
35+ else {std::cout << " Access test failed." << std::endl;}
36+ return 1 ;
37+ }
38+ std::cout << " Access test successful." << std::endl;
39+
40+ enforcer_destroy (enf);
41+ return 0 ;
42+ }
43+
You can’t perform that action at this time.
0 commit comments