{"id":994,"date":"2023-06-30T14:04:29","date_gmt":"2023-06-30T14:04:29","guid":{"rendered":"https:\/\/doc.bim.fm\/?post_type=docs&#038;p=994"},"modified":"2023-06-30T14:04:30","modified_gmt":"2023-06-30T14:04:30","slug":"authentificate","status":"publish","type":"docs","link":"https:\/\/doc.bim.fm\/index.php\/en\/docs\/api-3\/authentificate\/","title":{"rendered":"Authentificate"},"content":{"rendered":"\n<p>Most web APIs should implement a token-based authentication system. Token authentication is stateless and designed to be scalable. In a token-based authentication system, the client must first authenticate with the authentication provider. If successful, the client is issued a token, which is simply a cryptographically meaningful string of characters. The most common format for tokens is JSON Web Token, or JWT. When the client then needs to issue a request to an API, it adds this token as a header on the request. The server then validates the token found in the request header before completing the request.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" width=\"1906\" height=\"946\" src=\"https:\/\/doc.bim.fm\/wp-content\/uploads\/2021\/12\/Image1-2.png\" alt=\"\" class=\"wp-image-671\"\/><\/figure>\n\n\n\n<p>To do the majority of API calls using the nugget package, you will need to be logged in.<br>Here&#8217;s a quick example of how to<\/p>\n\n\n\n<p>Explanation :<\/p>\n\n\n\n<p>First, you need to define a BimfmApi object which is the main object of our nugget package.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>BimfmApi bimfmapi = new BimfmApi();<\/code><\/pre>\n\n\n\n<p>You will use it afterward for everything :<br>&#8211; Define the EC Project you want to target<br>&#8211; Log into the platform<br>&#8211; Use any API Calls on Project, Bcf, Quickshare and more !<br><\/p>\n\n\n\n<p>So let&#8217;s move on, we can define our target EC Project server as follows :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bimfmapi.mHttpRqs.BimFmUrl = \"https:\/\/dev.edifycad.com\/api\";<\/code><\/pre>\n\n\n\n<p>And now we just have to log in :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ResponseApi&lt;Tokens&gt; myTokenRqs = bimfmapi.token(\n    new Login() {\n        username = id,\n        password = password,\n        grant_type = \"password\",\n        scope = \"openid offline_access\"\n    });<\/code><\/pre>\n\n\n\n<p>You can easily check if the request went well with a simple check on the Status of the ResponseApi class :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if(myTokenRqs.Status == 200)\n{\n   Tokens myToken = myTokenRqs.Result;\n}<\/code><\/pre>\n\n\n\n<h2>C# API Full Example<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Login to the server\nBimfmApi bimfmapi = new BimfmApi();\nbimfmapi.mHttpRqs.BimFmUrl = \"https:\/\/dev.edifycad.com\/api\";\nResponseApi&lt;Tokens&gt; myTokenRqs = bimfmapi.token(\n    new Login() {\n        username = id,\n        password = password,\n        grant_type = \"password\",\n        scope = \"openid offline_access\"\n    });\n\nif(myTokenRqs.Status == 200)\n{\n   Tokens myToken = myTokenRqs.Result;\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"featured_media":0,"parent":992,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","doc_tag":[],"_links":{"self":[{"href":"https:\/\/doc.bim.fm\/index.php\/wp-json\/wp\/v2\/docs\/994"}],"collection":[{"href":"https:\/\/doc.bim.fm\/index.php\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/doc.bim.fm\/index.php\/wp-json\/wp\/v2\/types\/docs"}],"replies":[{"embeddable":true,"href":"https:\/\/doc.bim.fm\/index.php\/wp-json\/wp\/v2\/comments?post=994"}],"version-history":[{"count":1,"href":"https:\/\/doc.bim.fm\/index.php\/wp-json\/wp\/v2\/docs\/994\/revisions"}],"predecessor-version":[{"id":995,"href":"https:\/\/doc.bim.fm\/index.php\/wp-json\/wp\/v2\/docs\/994\/revisions\/995"}],"up":[{"embeddable":true,"href":"https:\/\/doc.bim.fm\/index.php\/wp-json\/wp\/v2\/docs\/992"}],"next":[{"title":"Lock file","link":"https:\/\/doc.bim.fm\/index.php\/en\/docs\/api-3\/lock-file\/","href":"https:\/\/doc.bim.fm\/index.php\/wp-json\/wp\/v2\/docs\/996"}],"wp:attachment":[{"href":"https:\/\/doc.bim.fm\/index.php\/wp-json\/wp\/v2\/media?parent=994"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/doc.bim.fm\/index.php\/wp-json\/wp\/v2\/doc_tag?post=994"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}