Skip to content

Commit

Permalink
Update fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
datakurre committed Sep 4, 2018
1 parent 470959c commit d0ff5f5
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"table_of_contents": null,
"text": {
"content-type": "text/html",
"data": "<p>For Plone sites requiring authentication to use Plone REST API (or limiting publishable content by permissions of specific user) you may use this guide to set up a safe method of authentication using <a href=\"http://plonerestapi.readthedocs.io/en/latest/authentication.html#json-web-tokens-jwt\">JWT</a> and <a href=\"https://github.com/motdotla/dotenv\">dotenv</a> configuration.</p>\n<p><strong>Note:</strong> In time of writing, Plone REST API only created tokens valid for the next 12 hours.</p>\n<p>In UNIX-like systems (OSX, Linux, Linux subsystem for Windows), a bash script would serve as a good way to retrieve the JWT from plone.restapi, by prompting for username and password:</p>\n<pre><code class=\"lang-bash\">bash\nread -p \"Username: \" USERNAME\nread -sp \"Password: \" PASSWORD\ncurl -s -X POST http://localhost:8080/Plone/@login -H 'Accept: application/json' -H 'Content-Type: application/json' --data-raw '{\"login\": \"'\"$USERNAME\"'\", \"password\": \"'\"$PASSWORD\"'\"}'\nexit\n</code></pre>\n<p>The above script will</p>\n<ol>\n<li>enter a new bash environment</li>\n<li>read username into environment variable</li>\n<li>read password into environment variable without displaying it when you type</li>\n<li>request authorization token</li>\n<li>exit bash to forget environment variables.</li>\n</ol>\n<p>This would give you a token as output:</p>\n<pre><code class=\"lang-json\">{\n \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmdWxsbmFtZSI6IkpvaG4gRG9lIiwic3ViIjoidXNlcm5hbWUiLCJleHAiOjE1Mjc0NDk0NTl9.epewKm09S6JXe07Ha6UNicN7v9MT32Rrkflxq2OqVRI\"\n}\n</code></pre>\n<p>Install dotenv and setup <code>.env</code> with the token so that it can be used in the Gatsby project:</p>\n<pre><code class=\"lang-bash\">// Install dotenv\nyarn install dotenv\n\n\n// In .env in the project folder\nTOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmdWxsbmFtZSI6IkpvaG4gRG9lIiwic3ViIjoidXNlcm5hbWUiLCJleHAiOjE1Mjc0NDk0NTl9.epewKm09S6JXe07Ha6UNicN7v9MT32Rrkflxq2OqVRI\n</code></pre>\n<p>Finally setup <code>gatsby-config.js</code> to use this in your project:</p>\n<pre><code class=\"lang-javascript\">// Top of your file\nrequire(\"dotenv\").config({\n path: '.env',\n});\n\n// In plugins list\nmodule.exports = {\n resolve: 'gatsby-source-plone',\n options: {\n baseUrl: 'http://localhost:8080/Plone/',\n token: process.env.TOKEN,\n }\n};\n</code></pre>",
"data": "<p>For Plone sites requiring authentication to use Plone REST API (or limiting publishable content by permissions of specific user) you may use this guide to set up a safe method of authentication using <a href=\"http://plonerestapi.readthedocs.io/en/latest/authentication.html#json-web-tokens-jwt\">JWT</a> and <a href=\"https://github.com/motdotla/dotenv\">dotenv</a> configuration.</p>\n<p><strong>Note:</strong> In time of writing, Plone REST API only created tokens valid for the next 12 hours.</p>\n<p>In UNIX-like systems (OSX, Linux, Linux subsystem for Windows), a bash script would serve as a good way to retrieve the JWT from plone.restapi, by prompting for username and password:</p>\n<pre><code class=\"lang-bash\">bash\nread -p \"Username: \" USERNAME\nread -sp \"Password: \" PASSWORD\ncurl -s -X POST http://localhost:8080/Plone/@login -H 'Accept: application/json' -H 'Content-Type: application/json' --data-raw '{\"login\": \"'\"$USERNAME\"'\", \"password\": \"'\"$PASSWORD\"'\"}'\nexit\n</code></pre>\n<p>The above script will</p>\n<ol>\n<li>enter a new bash environment</li>\n<li>read username into environment variable</li>\n<li>read password into environment variable without displaying it when you type</li>\n<li>request authorization token</li>\n<li>exit bash to forget environment variables.</li>\n</ol>\n<p>This would give you a token as output:</p>\n<pre><code class=\"lang-json\">{\n \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmdWxsbmFtZSI6IkpvaG4gRG9lIiwic3ViIjoidXNlcm5hbWUiLCJleHAiOjE1Mjc0NDk0NTl9.epewKm09S6JXe07Ha6UNicN7v9MT32Rrkflxq2OqVRI\"\n}\n</code></pre>\n<p>Install dotenv and setup <code>.secrets</code> with the token so that it can be used in the Gatsby project:</p>\n<pre><code class=\"lang-bash\">// Install dotenv\nyarn install dotenv\n\n\n// In .env in the project folder\nTOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmdWxsbmFtZSI6IkpvaG4gRG9lIiwic3ViIjoidXNlcm5hbWUiLCJleHAiOjE1Mjc0NDk0NTl9.epewKm09S6JXe07Ha6UNicN7v9MT32Rrkflxq2OqVRI\n</code></pre>\n<p>Finally setup <code>gatsby-config.js</code> to use this in your project:</p>\n<pre><code class=\"lang-javascript\">// Top of your file\nrequire(\"dotenv\").config({\n path: '.secrets',\n});\n\n// In plugins list\nmodule.exports = {\n resolve: 'gatsby-source-plone',\n options: {\n baseUrl: 'http://localhost:8080/Plone/',\n token: process.env.TOKEN,\n }\n};\n</code></pre>\n<p><strong>Important!</strong> Be careful in naming your environment variable file, because Gatsby will automatically include and make public all environment variables from files starting with <code>.env.</code> (e.g. <code>.env.production</code>).</p>",
"encoding": "utf-8"
},
"title": "Authenticating REST API calls",
Expand Down

0 comments on commit d0ff5f5

Please sign in to comment.