{
    "componentChunkName": "component---src-pages-blog-markdown-remark-fields-slug-js",
    "path": "/blog/flask-user-authentication",
    "result": {"data":{"markdownRemark":{"html":"<p>User authentication has become a fundamental part of almost every system in the world, with most websites and apps requiring users to login/logout or identify themselves in one way or another. In this article we will use SuperTokens to add user authentication to a Flask app.</p>\n<p>SuperTokens is an open source authentication solution that lets you quickly add login mechanisms and session management to your frontend and backend systems. It supports most login mechanisms such as Email &#x26; Password, Passwordless, Social login etc. We have two options to quickly get started with SuperTokens:</p>\n<ul>\n<li>Using the SuperTokens CLI</li>\n<li>Manually setting up SuperTokens</li>\n</ul>\n<h2 id=\"quick-start-with-supertokens-cli-recommended\" style=\"position:relative;\"><a href=\"#quick-start-with-supertokens-cli-recommended\" aria-label=\"quick start with supertokens cli recommended permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Quick start with SuperTokens CLI (Recommended)</h2>\n<p>An important thing to keep in mind is that SuperTokens requires a “core” to work correctly, the CLI uses a demo core that has been hosted to allow you to experiment with the SDKs quickly. This core should not be used in production.</p>\n<h3 id=\"about-the-supertokens-cli\" style=\"position:relative;\"><a href=\"#about-the-supertokens-cli\" aria-label=\"about the supertokens cli permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>About the SuperTokens CLI</h3>\n<p>SuperTokens provides a command line tool that can be used to quickly get started. It generates a fresh project with SuperTokens already integrated and enabled. If you are starting a new project and plan to use SuperTokens, this is the best way to get authentication added to your system. As a bonus the CLI also generates a fully functioning web application using the frontend of your choice. This UI layer uses a pre-built UI provided by the frontend SDKs with auth forms and redirects for social logins already built and handled for you.</p>\n<h3 id=\"initialize-the-cli\" style=\"position:relative;\"><a href=\"#initialize-the-cli\" aria-label=\"initialize the cli permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Initialize the CLI</h3>\n<p>To get started open your Terminal/Command Prompt and run the following command:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"26209449104042660000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`npx create-supertokens-app@latest`, `26209449104042660000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">npx create-supertokens-app@latest</code></pre></div>\n<p>You will be presented with the following options:</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 630px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/3d053250da5a5ea9e839304c9e3bf87d/bcb8c/cli-sample.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 28.48101265822785%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAYAAADDl76dAAAACXBIWXMAAAsTAAALEwEAmpwYAAABBUlEQVQY05WQ226CQBRF+ZEygK01DgMMF5GbiCIxqTWxifb/v2Q1My19bh9WTs4+yd47x1FKEUURWms70zQlzTK7x3FMGIYWKaXdkyRBGk1Kcq3Jsszq6/Ua3/dxurZlPB6ZponhcKDd7ajrmmEYaJoGE5jn+XdQmpJoTZHnhFrjSolwXTzPswRBgPN+u/Fxv/P5ePB2vdKMI8N+z3g60bYtZVnSdR1FUViMeV1VKK3x4pjA962RwTZsz2fUZmMrR0rxvFjYw4xJFkLguu4vT6aVEARC4P8YzTjXy4W+6xjHkb7vrbH50/yTOf2vOEVZsq0qtlVNsSkJVYSKYparFS/L13/zBXUGt9O6zsXyAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Sample of CLI output\"\n        title=\"Sample of CLI output\"\n        src=\"/static/3d053250da5a5ea9e839304c9e3bf87d/f058b/cli-sample.png\"\n        srcset=\"/static/3d053250da5a5ea9e839304c9e3bf87d/c26ae/cli-sample.png 158w,\n/static/3d053250da5a5ea9e839304c9e3bf87d/6bdcf/cli-sample.png 315w,\n/static/3d053250da5a5ea9e839304c9e3bf87d/f058b/cli-sample.png 630w,\n/static/3d053250da5a5ea9e839304c9e3bf87d/bcb8c/cli-sample.png 879w\"\n        sizes=\"(max-width: 630px) 100vw, 630px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<ul>\n<li><strong>App name</strong>: This is used as the folder name when generating the project.</li>\n<li><strong>Frontend Framework</strong>: Choose a framework you intend to use for your project. Some of the options include React, Next etc</li>\n<li><strong>Backend Framework</strong>: In this case we will select Python which allows us to present Flask when prompted.</li>\n<li><strong>Authentication Type</strong>: This lets you choose what authentication mechanism to use in your system. This option tells the CLI what ‘recipes’ and APIs need to be added, you can change or modify this later in code. In this example we will use email password, visit the documentation to see the full list of mechanisms and learn how they work.</li>\n</ul>\n<h3 id=\"understanding-the-generated-project\" style=\"position:relative;\"><a href=\"#understanding-the-generated-project\" aria-label=\"understanding the generated project permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Understanding the generated project</h3>\n<p>Once the CLI completes you can open the project in the IDE of your choice, for the sake of this example we will cover just the backend side of things.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 420px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/8b03579469ff213260245518cb0cd353/d10fb/structure.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 56.32911392405063%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAYAAAB/Ca1DAAAACXBIWXMAABYlAAAWJQFJUiTwAAABv0lEQVQoz4WS247SUBSGeQwTR2Booafd0tKWQzkLU4oDIxUdM0zA0cSY8V5vfRnfwof7zN6TQVTQi7/rz8peX/610oIIEtxGn7id8HbVI+mN6QwykuGM7jCj3U9JBjPcRhfH7yD8jqqHXjKkpC9IEyYzJqMWP77f8WZ7x83unu37e7YfPrPZfSK/3uGFPRw/2Q+fUqFqBRhOg7IR4FoRWeBT0l1k33RjNMNHl15EVO2G6qt6QoWybqPXXJ5ogtzV+RY8xfKaLF9tWOQ3LPMNk2xFtrymavmUNIuy7pxUQX40w6Oi25xZTc7CC3RDYDghuumr9JWaq3ReFf/VA9D0KJZNxHjGx68vabcTlustz9MrLl6siTtjnp2b+yE582+g4alHuu1jNztoNRdDhFhupKSZdUqafRT0Z2+fsFQ2qA3n3H7ZEEcRo3RFerkmvXzNOL1ikuVH1z4ONDyKmoNbr9NtWpR0D8MJ1APbi3H8FqYIKVas3/QIO4T+AlZMgtaIbPuORhQzW1yrZKPpkuk8V14mnmY5vfGc4XShziFP8VdCucrD6gGDYRNbeOonDeK+Sif8tqpOXfrW3j/e/hD4E+atWlOysmg3AAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Project Structure\"\n        title=\"Project Structure\"\n        src=\"/static/8b03579469ff213260245518cb0cd353/d10fb/structure.png\"\n        srcset=\"/static/8b03579469ff213260245518cb0cd353/c26ae/structure.png 158w,\n/static/8b03579469ff213260245518cb0cd353/6bdcf/structure.png 315w,\n/static/8b03579469ff213260245518cb0cd353/d10fb/structure.png 420w\"\n        sizes=\"(max-width: 420px) 100vw, 420px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n  </a>\n    </span></p>\n<p>The generated structure is fairly straightforward, if you need to set up a specific folder structure for your architecture it is better to do so now to avoid having to change imports later. Code snippets in this article will assume you have not changed the structure.</p>\n<h3 id=\"configuring-supertokens\" style=\"position:relative;\"><a href=\"#configuring-supertokens\" aria-label=\"configuring supertokens permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Configuring SuperTokens</h3>\n<p>The <code class=\"language-text\">config.py</code> file is where you configure SuperTokens.</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"823617780140262300\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`supertokens_config = SupertokensConfig(\n    connection_uri=&quot;https://try.supertokens.com&quot;)`, `823617780140262300`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">supertokens_config <span class=\"token operator\">=</span> SupertokensConfig<span class=\"token punctuation\">(</span>\n    connection_uri<span class=\"token operator\">=</span><span class=\"token string\">\"https://try.supertokens.com\"</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>The <code class=\"language-text\">connection_uri</code> property tells the SDK where the SuperTokens core is hosted, this can be a self hosted core or using the managed service SuperTokens provides. In this example we are using a demo core, this should be replaced with your own connection uri because the demo core is not suitable for production.</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"86539693015558670000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`app_info = InputAppInfo(\n    app_name=&quot;Supertokens&quot;,\n    api_domain=&quot;http://localhost:3001&quot;,\n    website_domain=&quot;http://localhost:3000&quot;,\n)`, `86539693015558670000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">app_info <span class=\"token operator\">=</span> InputAppInfo<span class=\"token punctuation\">(</span>\n    app_name<span class=\"token operator\">=</span><span class=\"token string\">\"Supertokens\"</span><span class=\"token punctuation\">,</span>\n    api_domain<span class=\"token operator\">=</span><span class=\"token string\">\"http://localhost:3001\"</span><span class=\"token punctuation\">,</span>\n    website_domain<span class=\"token operator\">=</span><span class=\"token string\">\"http://localhost:3000\"</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">)</span></code></pre></div>\n<p>The <code class=\"language-text\">api_domain</code> should be the domain where your API layer will be hosted (or localhost during testing), this is used for session management. Similarly the website_domain should be where your frontend will be hosted, if you are not building a frontend right now you can leave this as is or use a dummy domain.</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"86842656217090210000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`recipe_list = [\n    session.init(),\n    emailpassword.init(),\n    dashboard.init(),\n]`, `86842656217090210000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\">recipe_list <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\n    session<span class=\"token punctuation\">.</span>init<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    emailpassword<span class=\"token punctuation\">.</span>init<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    dashboard<span class=\"token punctuation\">.</span>init<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">]</span></code></pre></div>\n<p>The <code class=\"language-text\">recipe_list</code> tells the SuperTokens SDK what features and Authentication mechanisms you want to enable. In this example we are enabling session management which is the central feature for all authentication mechanisms and email password. We are also enabling the dashboard recipe, read the <a href=\"https://supertokens.com/docs/emailpassword/pre-built-ui/setup/user-management-dashboard/users-listing-and-details\" target=\"_blank\" rel=\"nofollow\">documentation</a> to understand what this is and how you can use it.</p>\n<h3 id=\"initialising-supertokens\" style=\"position:relative;\"><a href=\"#initialising-supertokens\" aria-label=\"initialising supertokens permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Initialising SuperTokens</h3>\n<p>Inside the <code class=\"language-text\">app.py</code> file you will see the following code (For the sake of this article we are only covering important snippets of the full file):</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"39564375885579860000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`from supertokens_python import (\n    get_all_cors_headers,\n    init,\n)\nfrom flask_cors import CORS\n\nfrom supertokens_python.framework.flask import Middleware\nimport config\n\ninit(\n    supertokens_config=config.supertokens_config,\n    app_info=config.app_info,\n    framework=config.framework,\n    recipe_list=config.recipe_list,\n)\n\napp = Flask(__name__)\nMiddleware(app)\nCORS(\n    app=app,\n    supports_credentials=True,\n    origins=&quot;http://localhost:3000&quot;,\n    allow_headers=[&quot;Content-Type&quot;] + get_all_cors_headers(),\n)`, `39564375885579860000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> supertokens_python <span class=\"token keyword\">import</span> <span class=\"token punctuation\">(</span>\n    get_all_cors_headers<span class=\"token punctuation\">,</span>\n    init<span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">)</span>\n<span class=\"token keyword\">from</span> flask_cors <span class=\"token keyword\">import</span> CORS\n\n<span class=\"token keyword\">from</span> supertokens_python<span class=\"token punctuation\">.</span>framework<span class=\"token punctuation\">.</span>flask <span class=\"token keyword\">import</span> Middleware\n<span class=\"token keyword\">import</span> config\n\ninit<span class=\"token punctuation\">(</span>\n    supertokens_config<span class=\"token operator\">=</span>config<span class=\"token punctuation\">.</span>supertokens_config<span class=\"token punctuation\">,</span>\n    app_info<span class=\"token operator\">=</span>config<span class=\"token punctuation\">.</span>app_info<span class=\"token punctuation\">,</span>\n    framework<span class=\"token operator\">=</span>config<span class=\"token punctuation\">.</span>framework<span class=\"token punctuation\">,</span>\n    recipe_list<span class=\"token operator\">=</span>config<span class=\"token punctuation\">.</span>recipe_list<span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">)</span>\n\napp <span class=\"token operator\">=</span> Flask<span class=\"token punctuation\">(</span>__name__<span class=\"token punctuation\">)</span>\nMiddleware<span class=\"token punctuation\">(</span>app<span class=\"token punctuation\">)</span>\nCORS<span class=\"token punctuation\">(</span>\n    app<span class=\"token operator\">=</span>app<span class=\"token punctuation\">,</span>\n    supports_credentials<span class=\"token operator\">=</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span>\n    origins<span class=\"token operator\">=</span><span class=\"token string\">\"http://localhost:3000\"</span><span class=\"token punctuation\">,</span>\n    allow_headers<span class=\"token operator\">=</span><span class=\"token punctuation\">[</span><span class=\"token string\">\"Content-Type\"</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> get_all_cors_headers<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">)</span></code></pre></div>\n<p>The <code class=\"language-text\">init</code> function is what you use to initialize the SuperTokens SDK, here you provide the configuration options defined in the <code class=\"language-text\">config.py</code> file.</p>\n<p>SuperTokens provides its own APIs and logic for handling authentication, the <code class=\"language-text\">Middleware</code> adds this to your system. This means that you do not need to implement your own APIs for handling authentication.</p>\n<p>We also use the <code class=\"language-text\">get_all_cors_headers</code> function provided by SuperTokens to add all the relevant CORS headers to the <code class=\"language-text\">CORS</code> middleware. Notice that the origin must match the <code class=\"language-text\">website_domain</code> set in the <code class=\"language-text\">config.py</code> file. To learn more about CORS read <a href=\"https://supertokens.com/blog/what-is-cross-origin-resource-sharing\" target=\"_blank\" rel=\"nofollow\">this article</a>.</p>\n<h3 id=\"run-the-project\" style=\"position:relative;\"><a href=\"#run-the-project\" aria-label=\"run the project permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Run the project</h3>\n<p>You can run the project by running the following command:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"60050250712635810000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`cd supertokens-flask-sample\nnpm run start`, `60050250712635810000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token builtin class-name\">cd</span> supertokens-flask-sample\n<span class=\"token function\">npm</span> run start</code></pre></div>\n<p>Notice that we use npm here, this is because the CLI internally generates a Node project to run both the backend and the frontend. This allows you to use the frontend project to test your backend integration. If you only want to run the backend project and test it out using Postman you can run the following commands:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"41720635734253600000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`cd backend\npip install virtualenv\nvirtualenv venv\nchmod +x venv/bin/activate\n. venv/bin/activate\npip install -r requirements.txt\npython app.py`, `41720635734253600000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token builtin class-name\">cd</span> backend\npip <span class=\"token function\">install</span> virtualenv\nvirtualenv venv\n<span class=\"token function\">chmod</span> +x venv/bin/activate\n<span class=\"token builtin class-name\">.</span> venv/bin/activate\npip <span class=\"token function\">install</span> -r requirements.txt\npython app.py</code></pre></div>\n<p>And that’s it, the project is set up and you can start building your actual project logic instead of spending time trying to build authentication from scratch. Here are some quick links for you:</p>\n<ul>\n<li>The <a href=\"https://supertokens.com/docs/guides\" target=\"_blank\" rel=\"nofollow\">official documentation</a> for a list of all features and authentication mechanisms</li>\n<li>Once you are ready to deploy your project be sure to use your own core by following the <a href=\"https://supertokens.com/docs/emailpassword/pre-built-ui/setup/core/saas-setup\" target=\"_blank\" rel=\"nofollow\">documentation</a></li>\n<li>The generated project adds some custom APIs for demonstration purposes, refer to <a href=\"https://supertokens.com/docs/emailpassword/pre-built-ui/securing-routes\" target=\"_blank\" rel=\"nofollow\">this page</a> to learn how to protect your APIs</li>\n</ul>\n<h2 id=\"manually-setting-up-supertokens-for-your-flask-backend\" style=\"position:relative;\"><a href=\"#manually-setting-up-supertokens-for-your-flask-backend\" aria-label=\"manually setting up supertokens for your flask backend permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Manually setting up SuperTokens for your Flask backend</h2>\n<p>An important thing to keep in mind is that SuperTokens requires a “core” to work correctly, the CLI uses a demo core that has been hosted to allow you to experiment with the SDKs quickly. This core should not be used in production.</p>\n<p>The full set of steps required to set up SuperTokens manually can be found in the <a href=\"https://supertokens.com/docs/emailpassword/pre-built-ui/setup/backend\" target=\"_blank\" rel=\"nofollow\">official documentation</a>.</p>\n<h3 id=\"install-the-supertokens-sdk\" style=\"position:relative;\"><a href=\"#install-the-supertokens-sdk\" aria-label=\"install the supertokens sdk permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Install the SuperTokens SDK</h3>\n<p>Run the following command:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"28889974695935705000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`pip install supertokens-python`, `28889974695935705000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">pip <span class=\"token function\">install</span> supertokens-python</code></pre></div>\n<h3 id=\"initialise-supertokens\" style=\"position:relative;\"><a href=\"#initialise-supertokens\" aria-label=\"initialise supertokens permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Initialise SuperTokens</h3>\n<p>To initialize the SDK, use the following code:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"40978482918016290000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`from supertokens_python import init, InputAppInfo, SupertokensConfig\nfrom supertokens_python.recipe import emailpassword, session\n\ninit(\n    app_info=InputAppInfo(\n        app_name=&quot;ST&quot;,\n        api_domain=&quot;http://localhost:3001&quot;,\n        website_domain=&quot;http://localhost:3000&quot;,\n    ),\n    supertokens_config=SupertokensConfig(\n        connection_uri=&quot;https://try.supertokens.com&quot;,\n    ),\n    framework='flask',\n    recipe_list=[\n        session.init(),\n        emailpassword.init()\n    ]\n)`, `40978482918016290000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> supertokens_python <span class=\"token keyword\">import</span> init<span class=\"token punctuation\">,</span> InputAppInfo<span class=\"token punctuation\">,</span> SupertokensConfig\n<span class=\"token keyword\">from</span> supertokens_python<span class=\"token punctuation\">.</span>recipe <span class=\"token keyword\">import</span> emailpassword<span class=\"token punctuation\">,</span> session\n\ninit<span class=\"token punctuation\">(</span>\n    app_info<span class=\"token operator\">=</span>InputAppInfo<span class=\"token punctuation\">(</span>\n        app_name<span class=\"token operator\">=</span><span class=\"token string\">\"ST\"</span><span class=\"token punctuation\">,</span>\n        api_domain<span class=\"token operator\">=</span><span class=\"token string\">\"http://localhost:3001\"</span><span class=\"token punctuation\">,</span>\n        website_domain<span class=\"token operator\">=</span><span class=\"token string\">\"http://localhost:3000\"</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    supertokens_config<span class=\"token operator\">=</span>SupertokensConfig<span class=\"token punctuation\">(</span>\n        connection_uri<span class=\"token operator\">=</span><span class=\"token string\">\"https://try.supertokens.com\"</span><span class=\"token punctuation\">,</span>\n    <span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n    framework<span class=\"token operator\">=</span><span class=\"token string\">'flask'</span><span class=\"token punctuation\">,</span>\n    recipe_list<span class=\"token operator\">=</span><span class=\"token punctuation\">[</span>\n        session<span class=\"token punctuation\">.</span>init<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n        emailpassword<span class=\"token punctuation\">.</span>init<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span>\n    <span class=\"token punctuation\">]</span>\n<span class=\"token punctuation\">)</span></code></pre></div>\n<p>The <code class=\"language-text\">init</code> function is what you use to initialize the SuperTokens SDK, here you provide the configuration options such as app name, api and website domains and the recipe list.</p>\n<p>The <code class=\"language-text\">connection_uri</code> property tells the SDK where the SuperTokens core is hosted, this can be a self hosted core or using the managed service SuperTokens provides. In this example we are using a demo core, this should be replaced with your own connection uri because the demo core is not suitable for production.</p>\n<p>The <code class=\"language-text\">api_domain</code> should be the domain where your API layer will be hosted (or <code class=\"language-text\">localhost</code> during testing), this is used for session management. Similarly the <code class=\"language-text\">website_domain</code> should be where your frontend will be hosted, if you are not building a frontend right now you can leave this as is or use a dummy domain.</p>\n<p>The <code class=\"language-text\">recipe_list</code> tells the SuperTokens SDK what features and Authentication mechanisms you want to enable. In this example we are enabling session management which is the central feature for all authentication mechanisms and email password. We are also enabling the dashboard recipe, read the <a href=\"https://supertokens.com/docs/emailpassword/pre-built-ui/setup/user-management-dashboard/users-listing-and-details\" target=\"_blank\" rel=\"nofollow\">documentation</a> to understand what this is and how you can use it.</p>\n<h3 id=\"add-the-supertokens-and-cors-middleware\" style=\"position:relative;\"><a href=\"#add-the-supertokens-and-cors-middleware\" aria-label=\"add the supertokens and cors middleware permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Add the SuperTokens and CORS middleware</h3>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"31588821942001435000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied!\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`from supertokens_python import get_all_cors_headers\nfrom flask import Flask, abort\nfrom flask_cors import CORS \nfrom supertokens_python.framework.flask import Middleware\n\napp = Flask(__name__)\nMiddleware(app)\n\nCORS(\n    app=app,\n    origins=[\n        &quot;http://localhost:3000&quot;\n    ],\n    supports_credentials=True,\n    allow_headers=[&quot;Content-Type&quot;] + get_all_cors_headers(),\n)\n\n# TODO: Add your own APIs here\n\n# This is required since if this is not there, then OPTIONS requests for\n# the APIs exposed by the supertokens' Middleware will return a 404\n@app.route('/', defaults={'u_path': ''})  \n@app.route('/<path:u_path>')  \ndef catch_all(u_path: str):\n    abort(404)`, `31588821942001435000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                <svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"py\"><pre class=\"language-py\"><code class=\"language-py\"><span class=\"token keyword\">from</span> supertokens_python <span class=\"token keyword\">import</span> get_all_cors_headers\n<span class=\"token keyword\">from</span> flask <span class=\"token keyword\">import</span> Flask<span class=\"token punctuation\">,</span> abort\n<span class=\"token keyword\">from</span> flask_cors <span class=\"token keyword\">import</span> CORS \n<span class=\"token keyword\">from</span> supertokens_python<span class=\"token punctuation\">.</span>framework<span class=\"token punctuation\">.</span>flask <span class=\"token keyword\">import</span> Middleware\n\napp <span class=\"token operator\">=</span> Flask<span class=\"token punctuation\">(</span>__name__<span class=\"token punctuation\">)</span>\nMiddleware<span class=\"token punctuation\">(</span>app<span class=\"token punctuation\">)</span>\n\nCORS<span class=\"token punctuation\">(</span>\n    app<span class=\"token operator\">=</span>app<span class=\"token punctuation\">,</span>\n    origins<span class=\"token operator\">=</span><span class=\"token punctuation\">[</span>\n        <span class=\"token string\">\"http://localhost:3000\"</span>\n    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\n    supports_credentials<span class=\"token operator\">=</span><span class=\"token boolean\">True</span><span class=\"token punctuation\">,</span>\n    allow_headers<span class=\"token operator\">=</span><span class=\"token punctuation\">[</span><span class=\"token string\">\"Content-Type\"</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">+</span> get_all_cors_headers<span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\n<span class=\"token punctuation\">)</span>\n\n<span class=\"token comment\"># TODO: Add your own APIs here</span>\n\n<span class=\"token comment\"># This is required since if this is not there, then OPTIONS requests for</span>\n<span class=\"token comment\"># the APIs exposed by the supertokens' Middleware will return a 404</span>\n<span class=\"token decorator annotation punctuation\">@app<span class=\"token punctuation\">.</span>route</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/'</span><span class=\"token punctuation\">,</span> defaults<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span><span class=\"token string\">'u_path'</span><span class=\"token punctuation\">:</span> <span class=\"token string\">''</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>  \n<span class=\"token decorator annotation punctuation\">@app<span class=\"token punctuation\">.</span>route</span><span class=\"token punctuation\">(</span><span class=\"token string\">'/&lt;path:u_path>'</span><span class=\"token punctuation\">)</span>  \n<span class=\"token keyword\">def</span> <span class=\"token function\">catch_all</span><span class=\"token punctuation\">(</span>u_path<span class=\"token punctuation\">:</span> <span class=\"token builtin\">str</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">:</span>\n    abort<span class=\"token punctuation\">(</span><span class=\"token number\">404</span><span class=\"token punctuation\">)</span></code></pre></div>\n<p>SuperTokens provides its own APIs and logic for handling authentication, the <code class=\"language-text\">Middleware</code> adds this to your system. This means that you do not need to implement your own APIs for handling authentication. You can see all the APIs that middleware adds <a href=\"https://app.swaggerhub.com/apis/supertokens/FDI\" target=\"_blank\" rel=\"nofollow\">here</a>.</p>\n<p>We also use the <code class=\"language-text\">get_all_cors_headers</code> function provided by SuperTokens to add all the relevant <code class=\"language-text\">CORS</code> headers to the CORS middleware. Notice that the origin must match the <code class=\"language-text\">website_domain</code>. To learn more about CORS read <a href=\"https://supertokens.com/blog/what-is-cross-origin-resource-sharing\" target=\"_blank\" rel=\"nofollow\">this article</a>. Make sure to also install <code class=\"language-text\">flask_cors</code>.</p>\n<h3 id=\"testing-the-integration\" style=\"position:relative;\"><a href=\"#testing-the-integration\" aria-label=\"testing the integration permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Testing the integration</h3>\n<p>You can now run your project to test that SuperTokens works correctly. For example you can try calling one of the APIs added by the SDK and see if they respond correctly.</p>\n<p>Here are some quick links for you:</p>\n<ul>\n<li>The <a href=\"https://supertokens.com/docs/guides\" target=\"_blank\" rel=\"nofollow\">official documentation</a> for a list of all features and authentication mechanisms</li>\n<li>Once you are ready to deploy your project be sure to use your own core by following the <a href=\"https://supertokens.com/docs/emailpassword/pre-built-ui/setup/core/saas-setup\" target=\"_blank\" rel=\"nofollow\">documentation</a></li>\n<li>The generated project adds some custom APIs for demonstration purposes, refer to <a href=\"https://supertokens.com/docs/emailpassword/pre-built-ui/securing-routes\" target=\"_blank\" rel=\"nofollow\">this page</a> to learn how to protect your APIs</li>\n</ul>\n<hr>\n<p>SuperTokens allows you to set up and start using authentication in a very simple and quick way, allowing you to focus on building your application specific logic instead of having to spend time building auth from scratch. The SuperTokens SLI lets you get started even quicker, allowing you to create a fresh application with SuperTokens integrated in under 15 minutes and as a bonus also gives you a ready to use frontend!</p>","frontmatter":{"date":"November 04, 2024","title":"Adding Authentication to Your Flask Backend with SuperTokens","cover":"flask-user-authentication.png","author":"Nemi Shah","description":"Learn how to seamlessly add authentication to your Flask backend using SuperTokens. This guide covers setting up authentication with the SuperTokens CLI or manual configuration, enabling you to focus on building application logic instead of authentication infrastructure."},"fields":{"slug":"/flask-user-authentication/"}},"site":{"siteMetadata":{"title":"SuperTokens Blog"}}},"pageContext":{"id":"7bb05f05-3aae-5793-b603-ca62f3f0159d","fields__slug":"/flask-user-authentication/","__params":{"fields__slug":"flask-user-authentication"}}},
    "staticQueryHashes": []}