{"componentChunkName":"component---src-templates-default-template-tsx","path":"/documentation/api/auth-api/","result":{"data":{"asciidoc":{"id":"5fd491cc-8e59-575d-94ca-1e49df87765f","html":"<div id=\"toc\" class=\"toc\">\n<div id=\"toctitle\">Table of Contents</div>\n<ul class=\"sectlevel1\">\n<li><a href=\"#_obtaining_a_backend_application_token_password_flow\">Obtaining a Backend Application Token (Password Flow)</a></li>\n<li><a href=\"#_obtaining_a_ui_application_token_ui_flow\">Obtaining a UI Application Token (UI Flow)</a></li>\n<li><a href=\"#_access_tokens_in_hiro_desktop_applications\">Access Tokens in HIRO Desktop Applications</a></li>\n<li><a href=\"#_example\">Example</a></li>\n</ul>\n</div>\n<div id=\"preamble\">\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>The HIRO API requires API users to be authenticated. API users need to obtain an access token from the <a href=\"https://core.engine.datagroup.de/help/specs/?url=definitions/auth.yaml\">HIRO Auth API</a> first, which is then used for subsequent API calls.</p>\n</div>\n<div class=\"paragraph\">\n<p>The HIRO API distinguishes two types of API usage:</p>\n</div>\n<div class=\"dlist\">\n<dl>\n<dt class=\"hdlist1\">Web Applications (including HIRO Desktop applications)</dt>\n<dd>\n<p>Frontend web applications that run in a web browser. These applications require the end user to login with his credentials.</p>\n</dd>\n<dt class=\"hdlist1\">Backend Services and Server Applications (including e.g. connectors)</dt>\n<dd>\n<p>Typically backend components or applications that run on a server. These applications use technical accounts and typically manage the credentials in the server application.</p>\n</dd>\n</dl>\n</div>\n<div class=\"paragraph\">\n<p>At the moment, HIRO’s Auth API provides two types of authentication flows:</p>\n</div>\n<div class=\"olist arabic\">\n<ol class=\"arabic\">\n<li>\n<p>Password flow</p>\n<div class=\"ulist\">\n<ul>\n<li>\n<p>For apps acting on their own (normally non-UI, such as Backend Services or Server Applications)</p>\n</li>\n<li>\n<p>Requires for the password to be sent directly to HIRO in order to request for the access token.</p>\n</li>\n</ul>\n</div>\n</li>\n<li>\n<p>UI flow</p>\n<div class=\"ulist\">\n<ul>\n<li>\n<p>For graphical interfaces, e.g.: browser apps</p>\n</li>\n<li>\n<p>The application will send the request for the token and HIRO will respond accordingly. However, the user\nneeds to login and authenticated first and then only the access token will be granted to the application.</p>\n</li>\n</ul>\n</div>\n</li>\n</ol>\n</div>\n<div class=\"paragraph\">\n<p>In order to use HIRO, you need to be authenticated and authorized. This means that you need to have a user\naccount that is tied to a <strong>username</strong> and <strong>password</strong>, which can be obtained from Almato AI.</p>\n</div>\n<div class=\"paragraph\">\n<p>The same user account and password can also be used to authenticate via API, but a separate application key\nneeds to be supplied as well. The application key consists of <strong>client ID</strong> and <strong>client secret</strong>, that are also\nobtained from Almato AI. When authenticating via API, it will always be in the context of an application, which\nmeans that you are using the API as a user but through an application. This means that you will be identified\nas a user using a certain application to access HIRO.</p>\n</div>\n<div class=\"paragraph\">\n<p>After authentication, the user will receive the AUTH token and this token can then be used (while it is valid)\nto make API calls. Auth tokens typically expire after 1 hour, unless configured differently.</p>\n</div>\n<div class=\"paragraph\">\n<p>For each new application (maybe a Connector, Acton Handler or service) that is accessing HIRO, a different application key\nmust be used, so that HIRO knows which application is accessing the system and data. Applications can be\nrevoked, without affecting other applications that need to access HIRO.</p>\n</div>\n</div>\n</div>\n<div class=\"sect1\">\n<h2 id=\"_obtaining_a_backend_application_token_password_flow\">Obtaining a Backend Application Token (Password Flow)</h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>A backend application is an application which runs as a backend service. The backend application typically operates independent from the activities of individual frontend users.\nAuthentication for these types of applications use the <code>OAUTH2 password</code> flow to obtain access tokens.</p>\n</div>\n<div class=\"paragraph\">\n<p>In order to obtain a token, the following request must be executed (example using curl command):</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-bash\" data-lang=\"bash\">curl -X POST -H 'Content-type: application/json' --data-binary '{\"client_id\": \"$id\", \"client_secret\": \"$secret\", \"username\": \"$user\", \"password\": \"$password\"}' 'https://core.engine.datagroup.de/api/auth/6/app'</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>with</p>\n</div>\n<div class=\"ulist\">\n<ul>\n<li>\n<p><code>client_id</code> being the id of the application</p>\n</li>\n<li>\n<p><code>client_secret</code> being the secret of the application</p>\n</li>\n<li>\n<p><code>username</code> being the username under which the application will operate</p>\n</li>\n<li>\n<p><code>password</code> being the password of the user</p>\n</li>\n</ul>\n</div>\n<div class=\"paragraph\">\n<p>This will return the following result:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-json\" data-lang=\"json\">{\n  \"_TOKEN\": \"$access token\",\n  \"_APPLICATION\": \"$client_id\",\n  \"_IDENTITY\": \"$ogit/name of the user\",\n  \"_IDENTITY_ID\": \"$id of the user\",\n  \"expires-at\": \"$expiration timestamp in ms\",\n  \"type\": \"Bearer\"\n}</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>Other option is to use OAUTH2 token flow which is same concept but use standard defined input and output</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-bash\" data-lang=\"bash\">curl -X POST -H 'Content-type: application/x-www-form-urlencoded' -H \"Authorization: Basic &lt;&lt;BASE64ENCODED($client_id:$client_secret)&gt;&gt;\" --data 'grant_type=password&amp;username=$username&amp;password=$password' 'https://core.engine.datagroup.de/api/auth/6/token'</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>with</p>\n</div>\n<div class=\"ulist\">\n<ul>\n<li>\n<p><code>client_id</code> being the id of the application</p>\n</li>\n<li>\n<p><code>client_secret</code> being the secret of the application</p>\n</li>\n<li>\n<p><code>username</code> being the username under which the application will operate</p>\n</li>\n<li>\n<p><code>password</code> being the password of the user</p>\n</li>\n</ul>\n</div>\n<div class=\"paragraph\">\n<p>This will return the following result:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-json\" data-lang=\"json\">{\n  \"access_token\": \"$token\",\n  \"expires_in\": \"$expiration time in seconds\",\n  \"token_type\": \"Bearer\",\n  \"refresh_token\": \"$refresh token\"\n}</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>The application can use the token to access the HIRO Graph API.</p>\n</div>\n</div>\n</div>\n<div class=\"sect1\">\n<h2 id=\"_obtaining_a_ui_application_token_ui_flow\">Obtaining a UI Application Token (UI Flow)</h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>A UI application is an application which only runs in the browser. Authentication must be done with the\n<code>OAUTH2 implicit</code> flow.</p>\n</div>\n<div class=\"paragraph\">\n<p>In order to start this flow, redirect the browser to:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-req\" data-lang=\"req\">GET https://core.engine.datagroup.de/api/auth/6/ui/?client_id={CLIENT_ID}&amp;redirect_url=https://another.example.com/my/app/</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>with <code>client_id</code> being the id of the application, and <code>redirect_url</code> the URL that will be redirected to upon\nsuccessful authentication. Please make sure that the <code>redirect_url</code> is correctly assigned to the application\nin HIRO IAM, so that the authentication flow works correctly. The Auth API will refuse to accept to unknown\nredirect URLs.</p>\n</div>\n<div class=\"paragraph\">\n<p>The user will be taken through the authentication process. If successful, the browser will finally be redirected to:</p>\n</div>\n<div class=\"listingblock\">\n<div class=\"content\">\n<pre class=\"highlight\"><code class=\"language-req\" data-lang=\"req\">GET https://another.example.com/my/app/#accessoken={token}</code></pre>\n</div>\n</div>\n<div class=\"paragraph\">\n<p>and the application can then parse the token from the <code>#</code> hash and remove it from the URL.</p>\n</div>\n</div>\n</div>\n<div class=\"sect1\">\n<h2 id=\"_access_tokens_in_hiro_desktop_applications\">Access Tokens in HIRO Desktop Applications</h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>The HIRO Desktop framework uses the mechanism for UI applications described above. The HIRO Desktop SDK handles the token management for your application, so that you as developer do not need to take care of authentication flow.</p>\n</div>\n</div>\n</div>\n<div class=\"sect1\">\n<h2 id=\"_example\">Example</h2>\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>For a step by step example on how to authenticate via API, please refer to the tutorial <a href=\"/7.0/tutorials/tutorial-first-steps-with-hiro/\">First Steps with HIRO</a>.</p>\n</div>\n</div>\n</div>","document":{"main":"HIRO Graph Auth API","title":"HIRO Graph Auth API","subtitle":""},"fields":{"toc":true,"location":["documentation","api","auth-api"]}},"sidebarYaml":{"id":"6d066bdd-c982-5a69-b909-a31e6fc044e0","showIndex":null}},"pageContext":{"id":"5fd491cc-8e59-575d-94ca-1e49df87765f","parent":"documentation"}},"staticQueryHashes":["1010459453","1010459453","2356112386","2356112386","2603905930","2603905930","3026652197","3026652197","3167850324","3167850324","63159454","63159454"]}