Difference between revisions of "Management API config"

From i2Rest
Jump to: navigation, search
(Created page with "=Request authorization= Most of requests to i2Rest Sever require authorization. Such requests as IBM i command call, I2Rest_API#run_program_AP...")
 
 
(26 intermediate revisions by 2 users not shown)
Line 1: Line 1:
=Request authorization=
+
{{DISPLAYTITLE:How to allow calls to management API}}
Most of requests to i2Rest Sever require authorization. Such requests as [[I2Rest_API#run_command_API|IBM i command call]], [[I2Rest_API#run_program_API|API call]] (except anonymous API call) and [[I2Rest_API#Management_APIs|management api call]] will not be served without OAuth2 token with appropriate [[I2Rest_scopes|scope]]. There is a [[OAuth2_object|OAuth2 object]], representing built-in authorization model. [[OAuth2_object#Settings_for_built-in_implementation|i2Rest built-in authorization model]] configuration options on example.<br>
+
[[Management_APIs|Management APIs]] includes functions that can be used to do some management stuff - change runtime parameters, query current status of server instance, etc. OAuth2 token with management_functions [[I2Rest_scopes#|scope]] is required for any management Api call.
<div id="Oauth2_obj_template">
+
 
    "OAuth2":
+
;Step 1
  {
+
:Register two users on IBM i.
      "scopes": {"management_functions" : {"description":"i2Rest management APIs call"},
+
;Step 2
                "run_program"         : {"description":"Run *PGM and *SRVPGM"},  
+
:Contact your system administrator for your IBM i server host name (or IP) and ''two'' available ports for "main" and "management" gates of your first i2Rest Server instance. Create file config.json (you can name it with any name and put it into any available IFS folder). Сopy and paste the snippet bellow. Replace with appropriate values highlighted with <b>bold</b> parts: host_name, ports, user (resource owner) and client.
                "run_command"         : {"description":"Run CL command"}
+
For clarity, differences with [[I2Rest_quick_config|Basic configuration]] are highlighted in <span style="background:#D3D3D3;">gray</span>:
  },
+
 
 +
 
 +
{
 +
    "gates":
 +
    {
 +
      "main"       : {"url":"http://'''<host_name>[:port] (for example api.i2rest.com:1234)'''"},
 +
      "management" : {"url":"http://'''<host_name>[:port] (for example api.i2rest.com:4321)'''"}
 +
    },
 +
<span style="background:#D3D3D3;">  "OAuth2":
 +
    {
 +
      "scopes": {"management_functions" : {"description":"i2Rest management APIs call"}
 +
      },
 
       "users":
 
       "users":
 
       {
 
       {
         "<span style="color:red;">USRX</span>":{"description":"<span style="color:red;">John Johnes</span>","valid_clients":{"<span style="color:red;">TSTCLNT</span>":{"scopes":["management_functions"]}}}
+
         "'''USRX'''":{"description":"'''John Johnes'''","valid_clients":{"'''TSTCLNT'''":{"scopes":["management_functions"]}}}
 
       },
 
       },
 
       "clients":
 
       "clients":
 
       {
 
       {
         "<span style="color:red;">TSTCLNT</span>":{"redirect_uri":"<span style="color:red;"><main gate URL></span>/oauth2/redirect",  
+
         "'''TSTCLNT'''":{"redirect_uri":"'''<main gate URL>'''/oauth2/redirect",  
 
                     "description":"Test client",  
 
                     "description":"Test client",  
 
                     "valid_scopes":["management_functions"],
 
                     "valid_scopes":["management_functions"],
Line 20: Line 31:
 
       },
 
       },
 
       "tokens": {"type":"token"},"codes":{"type":"code"}
 
       "tokens": {"type":"token"},"codes":{"type":"code"}
  }  
+
    }</span>  
<div>
+
  }
The snippet above shows us In general worlds i2Rest authorization model is something like '''WHAT''' is allowed and to '''WHOM''', and '''HOW''' it realized. '''WHAT''' parameters - are the "scopes", '''HOW''' parameters - "tokens", '''WHOM''' parameters - "users" and "clients" (built-in authorization model implies that both "users" and "clients" has to be registered as an IBM i users). So we can see that user '''USRX''' using client '''TSTCLNT''' is allowed to do some actions within '''"managment_functions"''' scope. And these are exactly the settings of Oauth2 object that we need to perform a Мanagement api call.<br>
+
 
 
+
Please take a look how to [[Auth_profile_SoapUI|obtain Oauth2 token from i2Rest Server with SoapUI]], and than proceed to [[Managment_API_SoapUI|Management api authorized call]].
==Мanagement API call==
 
So, what you have to do before we can test Мanagement API call to i2Rest Server:
 
:a) Register two users on IBM i - one for a "сlient" parameter and one for a "user" parameter.
 
:b) Fill the [[I2Rest_Advanced_Setup#Oauth2_obj_template|OAuth2 object template]] above with IBM i users values. Then add the snippet to your [[I2Rest_quick_config|basic server configuration]](with or without ssl protection) and put your new *.json anywhere on IBM i IFS.
 
:c) Restart server to apply your new configuration *.json.   
 
Now let's test the configuration obtaining [[Auth_profile_SoapUI|Oauth2 token with SoapUI]], and than proceed to [[Manage_API_SoapUI|Management api authorized call]].
 

Latest revision as of 14:26, 9 July 2020

Management APIs includes functions that can be used to do some management stuff - change runtime parameters, query current status of server instance, etc. OAuth2 token with management_functions scope is required for any management Api call.

Step 1
Register two users on IBM i.
Step 2
Contact your system administrator for your IBM i server host name (or IP) and two available ports for "main" and "management" gates of your first i2Rest Server instance. Create file config.json (you can name it with any name and put it into any available IFS folder). Сopy and paste the snippet bellow. Replace with appropriate values highlighted with bold parts: host_name, ports, user (resource owner) and client.

For clarity, differences with Basic configuration are highlighted in gray:


{
   "gates":
   {
      "main"       : {"url":"http://<host_name>[:port] (for example api.i2rest.com:1234)"},
      "management" : {"url":"http://<host_name>[:port] (for example api.i2rest.com:4321)"}
   },
   "OAuth2":
   {
     "scopes": {"management_functions" : {"description":"i2Rest management APIs call"}
     },
     "users":
     {
        "USRX":{"description":"John Johnes","valid_clients":{"TSTCLNT":{"scopes":["management_functions"]}}}
     },
     "clients":
     {
        "TSTCLNT":{"redirect_uri":"<main gate URL>/oauth2/redirect", 
                   "description":"Test client", 
                   "valid_scopes":["management_functions"],
                   "valid_grant_types":["authorization_code"]}
     },
     "tokens": {"type":"token"},"codes":{"type":"code"}
   } 
}
 

Please take a look how to obtain Oauth2 token from i2Rest Server with SoapUI, and than proceed to Management api authorized call.