{"componentChunkName":"component---src-pages-markdown-remark-fields-slug-js","path":"/engineering/guest-post/user-authentication-in-python/","result":{"data":{"markdownRemark":{"id":"b187fd34-4497-550b-af19-25792fd842f8","excerpt":"Authentication and user identity management are challenging tasks you are bound to run into when building applications. For example, you will need to create…","html":"<p>Authentication and user identity management are challenging tasks you are bound to run into when building applications. For example, you will need to create profiles for users, validate provided passwords, implement a password reset functionalities, manage user sessions (sometimes on multiple devices), manage social media authentication, and many others.</p>\n<p>You still have to work on other parts of your application, and you might not have a lot of time. A lot of developers might hack their way through authentication, but that could lead to improper implementations. It is not advisable to do this as you can create doorways for cyber-related attacks in your application.</p>\n<p>In this tutorial, you will learn how to properly implement user authentication and identity management in a Flask application.</p>\n<blockquote>\n<p>Here for the code alone? Head over to the <a href=\"#integrating-loginradius-with-python-and-flask\">implementation section</a> of this article or visit this <a href=\"https://gist.github.com/LordGhostX/01e9330dc4533a992a481fcd58fdd115\">GitHub gist</a> to browse demo code.</p>\n</blockquote>\n<h2 id=\"introduction\" style=\"position:relative;\"><a href=\"#introduction\" aria-label=\"introduction 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>Introduction</h2>\n<h3 id=\"what-is-user-authentication\" style=\"position:relative;\"><a href=\"#what-is-user-authentication\" aria-label=\"what is user authentication 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>What Is User Authentication?</h3>\n<p>User authentication is the process of validating a person’s identity to ascertain that they are who they claim to be. Authentication is achievable using passwords, one-time pins (OTP), biometrics, authentication apps, access tokens, certificates, and many more.</p>\n<h3 id=\"what-is-user-identity\" style=\"position:relative;\"><a href=\"#what-is-user-identity\" aria-label=\"what is user identity 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>What Is User Identity?</h3>\n<p>User identity is an entity used to identify a user of an application uniquely. Forms of user identifiers include full names, email addresses, system-generated values, and <a href=\"https://en.wikipedia.org/wiki/Universally_unique_identifier\">UUIDs</a>.</p>\n<h3 id=\"what-is-an-identity-provider\" style=\"position:relative;\"><a href=\"#what-is-an-identity-provider\" aria-label=\"what is an identity provider 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>What Is an Identity Provider?</h3>\n<p>An identity provider is a system that helps create, maintain, and manage user identity information. It also provides authentication services to external applications to ease their authentication flow and make it seamless.</p>\n<h2 id=\"what-is-authentication-in-python\" style=\"position:relative;\"><a href=\"#what-is-authentication-in-python\" aria-label=\"what is authentication in python 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>What Is Authentication in Python?</h2>\n<p>When referring to authentication in <a href=\"https://www.python.org\">Python</a>, we talk about user authentication concerning web applications built with it. Python is actively used in making web applications with many supporting frameworks, including but not limited to <a href=\"https://flask.palletsprojects.com/en/2.0.x/\">Flask</a>, Django, FastAPI, Bottle, and Hug.</p>\n<p>Every web application built with Python at one point or another would need to implement user authentication features. This article will cover implementing authentication and proper handling of user identity information using <a href=\"https://loginradius.com\">LoginRadius</a> and Flask.</p>\n<h2 id=\"getting-started-with-loginradius\" style=\"position:relative;\"><a href=\"#getting-started-with-loginradius\" aria-label=\"getting started with loginradius 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>Getting Started with LoginRadius</h2>\n<h3 id=\"what-is-loginradius\" style=\"position:relative;\"><a href=\"#what-is-loginradius\" aria-label=\"what is loginradius 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>What Is LoginRadius?</h3>\n<p><a href=\"https://accounts.loginradius.com/auth.aspx?action=register&#x26;return_url=https://dashboard.loginradius.com/login\">LoginRadius</a> is a cloud-based consumer identity and access management (CIAM) platform that allows seamless user authentication and SSO integration into your application. LoginRadius is simple to use, completely secure, and highly customizable.</p>\n<p>To proceed with this tutorial, you will need an account with LoginRadius. If you have not created one before now, create one on the <a href=\"https://accounts.loginradius.com/auth.aspx?action=register&#x26;return_url=https://dashboard.loginradius.com/login\">LoginRadius website</a>.</p>\n<h3 id=\"benefits-of-using-loginradius\" style=\"position:relative;\"><a href=\"#benefits-of-using-loginradius\" aria-label=\"benefits of using loginradius 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>Benefits of Using LoginRadius</h3>\n<ul>\n<li>It simplifies user management.</li>\n<li>It provides unmatched data, user, and account security.</li>\n<li>It ensures automatic privacy compliance.</li>\n<li>It integrates seamlessly into your applications.</li>\n<li>It provides scalable infrastructure.</li>\n</ul>\n<h1 id=\"integrating-loginradius-with-python-and-flask\">Integrating LoginRadius with Python and Flask</h1>\n<ul>\n<li>This section covers setting up the demo application that we will be integrating LoginRadius into in the remaining parts of the tutorial.</li>\n<li>It also covers LoginRadius integration with the Python and Flask demo application code.</li>\n</ul>\n<h3 id=\"acquiring-loginradius-api-credentials\" style=\"position:relative;\"><a href=\"#acquiring-loginradius-api-credentials\" aria-label=\"acquiring loginradius api credentials 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>Acquiring LoginRadius API Credentials</h3>\n<p>Login to your <a href=\"https://accounts.loginradius.com/auth.aspx?return_url=https://dashboard.loginradius.com/login\">LoginRadius dashboard</a>, then navigate to the app you want to integrate with Python (LoginRadius will set up a free app for you when you create an account).</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 48.76923076923077%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsTAAALEwEAmpwYAAACC0lEQVQoz3VSy2oUQRQtdxpRMRGyMAFF1KhEicbFEGciJiiI4CLiwrUBF/6EC3/FRX7AlV8ggkFMFjIagk5Pz0y/u6u6uqv6eG81Mxux4FDU69Q5516xcP8ZljvPIa50sfXqLUxdIcsy6NogkZrWNer/gM+iQiNTGkmSIKV34uzqNhbXn0Jc6mDz5Rt4nodvB4fo/zyC54/gDX0MPMLwX0zP/OGY0N4V5289xOLaY4iLd9Hd2UVRFPjjDeGPxgjCEFGcIM8LZHlOaOfZOsudqkE8xiCh+1FECm9uYn71EcTSPXRf7ALWYjKZIElTIoshpXT2KkZVEdrZWAMeh/I33v34gPf9PXwN+xDnSOGFO9st4c5rNE3jsispQ20sElVDaSIwBjXBTMGEDTBQIT6N9vE5OcDHX8cQZ270MH97C2J53RHWVJQ4ndorkBJUSR9ojYLU5hQJzwzeM7qG1ZbIG3w5jiFOXt3A3PWuy7BHlrnKPhUjCIIWlKOmh6xck1KOwvd9FwvHoZSCaSwsyc1pLU5de4DTK91ZURo6TAoFWbGtxv1sKVcenF0uFVJZujtpId1n01GVigk3wLanGVoiiCm3UNZEameErLAsSyIskZLFSBmUpnH7baYWRwH14dxKDwtrT3DicsdVWSnpeswfTzAk6yFZZpspge1zOzG4R4Mwcpb5o0KV2Pvu4y/EuKSF93wBVwAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"LoginRadius Dashboard\"\n        title=\"LoginRadius Dashboard\"\n        src=\"/static/f9afbe9d84c5cdd2af1ccf545eea1e27/e5715/pw6s1mqnn-yrtard7nbx.png\"\n        srcset=\"/static/f9afbe9d84c5cdd2af1ccf545eea1e27/a6d36/pw6s1mqnn-yrtard7nbx.png 650w,\n/static/f9afbe9d84c5cdd2af1ccf545eea1e27/e5715/pw6s1mqnn-yrtard7nbx.png 768w,\n/static/f9afbe9d84c5cdd2af1ccf545eea1e27/29007/pw6s1mqnn-yrtard7nbx.png 1600w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p>Next, head over to the <code>Configuration</code> tab on the LoginRadius sidebar (left side of the screen).</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 40.76923076923077%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAICAIAAAB2/0i6AAAACXBIWXMAAAsTAAALEwEAmpwYAAABO0lEQVQY012R3UrDMBzFA7KCY+jA4aWog1ZX8etGhY3VOZnXE7zx4XwM38J7X0DXrU2az3ZN1vlvw4p6OAn/0hx+6SlqXz0d9KdO78GfvIbhnDGmsiURabbMai9/KeIplynGWEiJWmejzvWk4fa90cvX94xShkmSMC6E/GdeWsAbMOcixgS1/WD/8tHp3rrDKTxTxsL5Ag7lWgMnz3NYlqm1Xlcqqp0xjnZ7Qedi3OjeucFzFGNtjNYGDlit/qrYCMI4YWjndLh3Pm4cl2EgK6UwJmmaVbJsIJdwY4wlmyr89jFDrZNB2793LBkTqCGK4oQyqZTMMrhILUss1oUNv39GqOn1t73B1uGNV5HhawmlZV1SwYIBuoEdZr0hWwnOynATwkdleBFhuCb8JWgrr1WP0Jg21sasSEJ/AIwagyczfrINAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"LoginRadius Configuration\"\n        title=\"LoginRadius Configuration\"\n        src=\"/static/2541852fcbc5a0ae25b8107c1e6fe890/e5715/i_alrgdnugpmtschkuuj.png\"\n        srcset=\"/static/2541852fcbc5a0ae25b8107c1e6fe890/a6d36/i_alrgdnugpmtschkuuj.png 650w,\n/static/2541852fcbc5a0ae25b8107c1e6fe890/e5715/i_alrgdnugpmtschkuuj.png 768w,\n/static/2541852fcbc5a0ae25b8107c1e6fe890/29007/i_alrgdnugpmtschkuuj.png 1600w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p>Your API credentials are located under the <code>API Key And Secret</code> section. Once you have retrieved this, copy the <code>APP Name</code>, <code>API Key</code>, and <code>API Secret</code> and store them somewhere secure and easily retrievable.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 53.38461538461539%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAIAAADwazoUAAAACXBIWXMAAAsTAAALEwEAmpwYAAABAklEQVQoz41Sy07EMAzMv/M1fAMS4obEgQO3PYEAsW3zqJPm2ZDCJEVQrdRdRpYTWbVnxin7/EP5+jeWBjYSDZz3wyCVSvOcc8YYpNyQUqvNGccKVFBfR7DJOiEU5wL9mIJLy7xXNFrnvA8hhhBchQdQiyn9NGMM5pVSqu4GXBYckHVJPCMy3SAcCELyIfrKU3OO8V2Hg4rV4W6zsR2XatQjmd9QZPw0PX7o21eLj8pONzxb2FjVnqIs5ax0bNsceykkbYMLcqTvntX1gc4xg5a0Xl/oBBdXxuC2G6rnbUilrdZPR3N13928mD1yluZcXzKmbfiY8Ddwlx4692bmvYV/A5sxgDde+J2+AAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"LoginRadius API credentials\"\n        title=\"LoginRadius API credentials\"\n        src=\"/static/c287d39ecf351e1775a3e5e8d1c4ba8b/e5715/7lev6yc_ebtxcg62wrbe.png\"\n        srcset=\"/static/c287d39ecf351e1775a3e5e8d1c4ba8b/a6d36/7lev6yc_ebtxcg62wrbe.png 650w,\n/static/c287d39ecf351e1775a3e5e8d1c4ba8b/e5715/7lev6yc_ebtxcg62wrbe.png 768w,\n/static/c287d39ecf351e1775a3e5e8d1c4ba8b/1acf3/7lev6yc_ebtxcg62wrbe.png 1596w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<h3 id=\"whitelisting-your-domains\" style=\"position:relative;\"><a href=\"#whitelisting-your-domains\" aria-label=\"whitelisting your domains 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>Whitelisting Your Domains</h3>\n<p>LoginRadius requires you to whitelist domains you will be integrating with your app. To whitelist, a domain, scroll down to the <code>Whitelist Your Domain</code> section in the <code>Configuration</code> tab of your app dashboard and add it.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 45.69230769230769%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAIAAAC9o5sfAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA+klEQVQoz41RSVLEMAzMs3kAP+IFnLhy5UrILCRxkokXyZJtOhkCE+ZCV5eskktuqV0552drrXNr4gJRjMIRkGvyQ2K+pfOhCsTv9UdzOB5P57pphmFEvw/BexBn8CuZueyhqhXeMONkhmGhGXtj2q7v+h7xs+0QQRQRmONvZy4iUnEUSRlIK5Ysl7wd5TvNy8VemdGM5YhIRMsdSHOQdF+/vnOhCOUIq5LqKqwbU8np8eXw8Fz/VdzgWSqMDmPgNiyRPXpLnSXdA+tZH15Pc4gYW2S28zhNtHzSDkkkq9xWMKaqmPHy9NZajsvOEIlL9V/AgrD9NBNx/AKMSQv4EBNfaQAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Domain Whitelisting\"\n        title=\"Domain Whitelisting\"\n        src=\"/static/3217ad727ff6eb3316cc85e9fee569e7/e5715/5ng50vbosmuhdhfuz-gi.png\"\n        srcset=\"/static/3217ad727ff6eb3316cc85e9fee569e7/a6d36/5ng50vbosmuhdhfuz-gi.png 650w,\n/static/3217ad727ff6eb3316cc85e9fee569e7/e5715/5ng50vbosmuhdhfuz-gi.png 768w,\n/static/3217ad727ff6eb3316cc85e9fee569e7/29007/5ng50vbosmuhdhfuz-gi.png 1600w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<blockquote>\n<p>By default, LoginRadius whitelists your local computer (localhost).</p>\n</blockquote>\n<h3 id=\"installing-loginradius-python-sdk\" style=\"position:relative;\"><a href=\"#installing-loginradius-python-sdk\" aria-label=\"installing loginradius python 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>Installing LoginRadius Python SDK</h3>\n<p>We need to install the LoginRadius Python SDK. It provides functionalities that allow Python programs to communicate with LoginRadius APIs.</p>\n<p>In the terminal, type:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"bash\" data-index=\"0\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">pip install LoginRadius-v2 requests cryptography pbkdf2</span></span></code></pre>\n<h3 id=\"setting-up-our-flask-server\" style=\"position:relative;\"><a href=\"#setting-up-our-flask-server\" aria-label=\"setting up our flask server 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>Setting up Our Flask Server</h3>\n<p>First, we need to install the Flask framework from PyPI. In the terminal, type:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"bash\" data-index=\"1\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">pip install flask</span></span></code></pre>\n<p>After that, create a file named <code>server.py</code> and save the following code in it:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"python\" data-index=\"2\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk15\">from</span><span class=\"mtk1\"> flask </span><span class=\"mtk15\">import</span><span class=\"mtk1\"> *</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">app = Flask(</span><span class=\"mtk12\">__name__</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">app.config[</span><span class=\"mtk8\">&quot;SECRET_KEY&quot;</span><span class=\"mtk1\">] = </span><span class=\"mtk8\">&quot;SECRET_KEY&quot;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk11\">@app.route</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;/&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">def</span><span class=\"mtk1\"> </span><span class=\"mtk11\">index</span><span class=\"mtk1\">():</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">return</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&quot;Hello World!&quot;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk15\">if</span><span class=\"mtk1\"> </span><span class=\"mtk12\">__name__</span><span class=\"mtk1\"> == </span><span class=\"mtk8\">&quot;__main__&quot;</span><span class=\"mtk1\">:</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    app.run(</span><span class=\"mtk12\">debug</span><span class=\"mtk1\">=</span><span class=\"mtk4\">True</span><span class=\"mtk1\">)</span></span></code></pre>\n<p>When you run the <code>server.py</code> script and open your browser, you will get a response similar to the image below:</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 44.61538461538462%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAIAAAC9o5sfAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA40lEQVQoz2OI082Mtck2MojXlwj3MWoNNu8Nsepz125xVK53Uql3VKl31WgylAtVk3BQEbdHQwyxhoVeWjWWaoVG0qnmSpmWKjlWqjmmCpkm8lnmSrlAZKVWoK8QoSHjoyblrSrphYwYLLVjjdVjzdRjLbUTdJQCtBT9QEjB10gzwtYszcYk1cU2x9Eq29Y0w0w3yVAj1kgzDo4YDu49vmfn4Z3bDp46cfnmtYfXL9+/fgWGroLQtSsPrl29d+3KPQgXGTH8+/f3778/f//+/v//338SAQMy5x+JgOE/BWDgNAMA2huISzFg+LkAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Hello World\"\n        title=\"Hello World\"\n        src=\"/static/1947174e905bcfeb6e51672185574dd9/e5715/vordrrnvz-vekwuickak.png\"\n        srcset=\"/static/1947174e905bcfeb6e51672185574dd9/a6d36/vordrrnvz-vekwuickak.png 650w,\n/static/1947174e905bcfeb6e51672185574dd9/e5715/vordrrnvz-vekwuickak.png 768w,\n/static/1947174e905bcfeb6e51672185574dd9/525d3/vordrrnvz-vekwuickak.png 1090w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<h3 id=\"initializing-the-loginradius-sdk\" style=\"position:relative;\"><a href=\"#initializing-the-loginradius-sdk\" aria-label=\"initializing the loginradius 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>Initializing the LoginRadius SDK</h3>\n<p>Update the <code>server.py</code> file with the code below:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"python\" data-index=\"3\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk15\">from</span><span class=\"mtk1\"> LoginRadius </span><span class=\"mtk15\">import</span><span class=\"mtk1\"> LoginRadius </span><span class=\"mtk15\">as</span><span class=\"mtk1\"> LR</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">LR.API_KEY = </span><span class=\"mtk8\">&quot;API Key&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">LR.API_SECRET = </span><span class=\"mtk8\">&quot;API Secret&quot;</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">loginradius = LR()</span></span></code></pre>\n<p>Replace the values of the <code>API_KEY</code> and <code>API_SECRET</code> variables with your LoginRadius application keys we saved earlier.</p>\n<h2 id=\"setting-up-user-registration\" style=\"position:relative;\"><a href=\"#setting-up-user-registration\" aria-label=\"setting up user registration 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>Setting up User Registration</h2>\n<p>To register users, you have to redirect them from your application to your LoginRadius Auth Page (IDX). Each LoginRadius app has a custom IDX. You can access it with the following URL pattern.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"\" data-index=\"4\"><code class=\"grvsc-code\"><span class=\"grvsc-line\">https://{APP_NAME}.hub.loginradius.com/auth.aspx?action={AUTH_ACTION}&return_url={RETURN_URL}</span></code></pre>\n<ul>\n<li>The <code>APP_NAME</code> parameter refers to your LoginRadius app name, which you can retrieve from the <code>API Key And Secret</code> section in the <code>Configuration</code> tab of your dashboard.</li>\n<li>The <code>AUTH_ACTION</code> parameter refers to the authentication action you’re attempting to perform. It is either <code>register</code> or <code>login</code>.</li>\n<li>The <code>RETURN_URL</code> parameter refers to the URL LoginRadius should redirect your users to after successful authentication. It is usually a route on your application server.</li>\n</ul>\n<p>Update the <code>server.py</code> file with the code below:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"python\" data-index=\"5\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk1\">LR_AUTH_PAGE = </span><span class=\"mtk8\">&quot;https://&lt;APP_NAME&gt;.hub.loginradius.com/auth.aspx?action=</span><span class=\"mtk4\">{}</span><span class=\"mtk8\">&return_url=</span><span class=\"mtk4\">{}</span><span class=\"mtk8\">&quot;</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk11\">@app.route</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;/register/&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">def</span><span class=\"mtk1\"> </span><span class=\"mtk11\">register</span><span class=\"mtk1\">():</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk3\"># redirect the user to our LoginRadius register URL</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">return</span><span class=\"mtk1\"> redirect(LR_AUTH_PAGE.format(</span><span class=\"mtk8\">&quot;register&quot;</span><span class=\"mtk1\">, request.host_url))</span></span></code></pre>\n<p>In the code above, we created a <code>register</code> route that redirects users to our LoginRadius registration IDX. We also set our <code>AUTH_ACTION</code> to “register” and our <code>RETURN_URL</code> to our application home page.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 85.23076923076923%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAARCAIAAABSJhvpAAAACXBIWXMAAAsTAAALEwEAmpwYAAACqklEQVQ4y3WS/08SYRzH+ZfqF7Qm2dpaWtn8chyQyzZFnctVP7S5taUFLuAAVxuSWq2ttrasrRTTFZVDzMGR4N2BIOLANUVEhE7ggDueHu4UNemz1557P8/e793n+ewRiWvaq88pqyQdZ8931V7slVzo4bdKsaTjTK0SanFNR7VEWcWvp6vaTolvlBFJcR0E4UFdmBTHWnAtXBUuA4JroW7GNXAVDGUhIJJ5DegBCIXBrXzZ2OsbMYUm74Ze3l590Rd6rQwMN5IaqRe77huChjIilNQLSEl9u8/UuWy+5R/tXjb3+Ee6/c+6/OaewEin39zpG77pfSqnjDLSUI4chiH3Q2/sCV8esFt7O1v0TjyTjKeTsb1ELL0LALAlvNIljfyI/zDcSg01uAc/xhxgL2+xWGyzNrvNPvv9B8RqtSajO4t/1tAlnaxy2Dt02a0ej87Dn6yuhUi+CILweDzh9QgoADy50rSkrdy2gjJecavfb5bCBY7NZDKpVIqm6XQ6XWAL8BBPBhFC99/wJbfq3eZPwIF0NsMeKSafAyxw7QalBCanToTlJNZIPel339mMTbIsoOkUwzBZJgsRBAw7kyvNRKW2ZZQe9Rjb5vrmvV9gh1kmw7EcKAJIkSvmC3m+7ZXmhUEZcXJg8G04sMaZB3M+O+Brndl+vmEd2/j6m4kLJzDc8k2lwPXoQefHwg3T/Z9WnYI1mtud2MYn4ngsl9wPJ4KIVd2+UHpkx8OUXkEY6u2qDz6nMO2SHbbNlb5skdsP45pWj7HytOs8j8aj9rI7B69Op6Hg+C2cNhwY+u8joUrXkFHGJlJ3L/BqLDJjCluGw1PmyGcIFKbw1Ghk+mHwLULyFy5xEEYWtS2uxxDEpbmGq+sc/fWOAQgUR/TAVadKsJX4pUEJ7C8IDKqugjxwhgAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"LoginRadius Login Page\"\n        title=\"LoginRadius Login Page\"\n        src=\"/static/813dfc4b51a3c6e998e0467ee788f277/e5715/smn-8jr5ahgmhtynezje.png\"\n        srcset=\"/static/813dfc4b51a3c6e998e0467ee788f277/a6d36/smn-8jr5ahgmhtynezje.png 650w,\n/static/813dfc4b51a3c6e998e0467ee788f277/e5715/smn-8jr5ahgmhtynezje.png 768w,\n/static/813dfc4b51a3c6e998e0467ee788f277/29007/smn-8jr5ahgmhtynezje.png 1600w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<blockquote>\n<p>NOTE: Don’t forget to replace the &#x3C;APP_NAME> placeholder with your LoginRadius app name we saved earlier.</p>\n</blockquote>\n<h3 id=\"authenticating-registered-users-user-login\" style=\"position:relative;\"><a href=\"#authenticating-registered-users-user-login\" aria-label=\"authenticating registered users user login 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>Authenticating Registered Users (User Login)</h3>\n<p>To authenticate registered users, you have to redirect them to your IDX page, passing “login” as the <code>AUTH_ACTION</code>.</p>\n<p>Update the <code>server.py</code> file with the code below:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"python\" data-index=\"6\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk11\">@app.route</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;/login/&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">def</span><span class=\"mtk1\"> </span><span class=\"mtk11\">login</span><span class=\"mtk1\">():</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    access_token = request.args.get(</span><span class=\"mtk8\">&quot;token&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">if</span><span class=\"mtk1\"> access_token </span><span class=\"mtk4\">is</span><span class=\"mtk1\"> </span><span class=\"mtk4\">None</span><span class=\"mtk1\">:</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk3\"># redirect the user to our LoginRadius login URL if no access token is provided</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk15\">return</span><span class=\"mtk1\"> redirect(LR_AUTH_PAGE.format(</span><span class=\"mtk8\">&quot;login&quot;</span><span class=\"mtk1\">, request.base_url))</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">return</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&quot;You have successfully logged in!&quot;</span></span></code></pre>\n<blockquote>\n<p>When LoginRadius successfully authenticates a user, it attaches a <code>token</code> parameter to the <code>REDIRECT_URL</code> before redirecting your user there. This parameter contains the <a href=\"https://en.wikipedia.org/wiki/Access_token\">access token</a> of the user that we authenticated.</p>\n</blockquote>\n<p>In the code above, we redirect users to our LoginRadius login IDX if the <code>token</code> parameter is absent (this means LoginRadius did not redirect the user here). We also set our <code>AUTH_ACTION</code> to “login” and our <code>RETURN_URL</code> to our login page.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 85.23076923076923%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAARCAIAAABSJhvpAAAACXBIWXMAAAsTAAALEwEAmpwYAAACsklEQVQ4y3VS609ScRjmT8qtRVqhra118ZLK4YBazim2am31pbk+5BScwuGi2Zfaaqu+pctKTOcyTSSVcww8F1wc1kq0cxDkIgii50DvgUGa9O758Pze8zznfX7vfjL5ufbySu1pRceZ8zerLt5VXLidO2rlio6KSq38bHu5QgsAQUVV58mKthOnrpfJW8vkNwAyFW4EIDmgBKYiMCBqwtRMWPJ9JW4AguKYCodPBqQgBsjUjBktAGEwQCNj7KSfWNmxO95nt74/vc++aPUMVZN9DbSh2WMFfREylDIV0eYZfsC+HF63DfptjzcmBjdsQ5sTw78nLf5x7OdYF/tKTZkBRf0R80PfayLKZrNZPsBzHB/eDge2AjzPczwPTTzqU7kHNIf0f80ttLXW1fd+a1mMp22TH+25ms3VF/t8JBAiYj6UNKpLmxnrVZd+hFuAIf7NDYaWimEYiqLgCE1nxNuwaigdu4m2VLv0o5wDdEJGzGQygiCIokTEbEaKHWERafJ/zJdcujfc16yQje8m9g5VMpWEJhFhVSSmoY+ZNRRWTw91u+5xW+MCmBOx1F4qvS9VOp0GDmZn1NtIloqtpk2o29Jq73Iw05DwQDjI7AvJWCK2swN+EYJL2/Y2LvapyeMLY8yaZax+6tG8xw46bi88FXSthNlUMglj4V95s3JG14Sb0ELyI+baye4xdhl0nvi66de7D0FnLBoLhUKJ3YRkDrPIJ337ovTIjpppU9Oq+cqCbpRxSrFFQdq5IBwIQn75ObMXwQda3JbS277s7h3hHUV1Kr6b3kkCyd95JeqDhaH/PhJauoaGsdSR/cYfbxe312aC7tng6lyImtumgHwOuh0h5rl/WklhariwhIIZ+WZQEv0AhOi/5tRXL/XULPXm0FNziNc5dXmZhJUBlMT+ANjYr91wzuSxAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"LoginRadius Login Page\"\n        title=\"LoginRadius Login Page\"\n        src=\"/static/4a194cdf7efcbd7ff63dbe07e645ce76/e5715/7gs3xz6qhxhas7qgtjma.png\"\n        srcset=\"/static/4a194cdf7efcbd7ff63dbe07e645ce76/a6d36/7gs3xz6qhxhas7qgtjma.png 650w,\n/static/4a194cdf7efcbd7ff63dbe07e645ce76/e5715/7gs3xz6qhxhas7qgtjma.png 768w,\n/static/4a194cdf7efcbd7ff63dbe07e645ce76/29007/7gs3xz6qhxhas7qgtjma.png 1600w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 25.384615384615383%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAFCAIAAADKYVtkAAAACXBIWXMAAAsTAAALEwEAmpwYAAAApUlEQVQY02OIMSyw0cowkUv10G300m/yBCK9JieNGi1JP0URO0URByVRB0VREAlHcC6Dq16KtVaGhUaSkXqkqWa0uU68o3m2k0WunUm6tWGylWGypUGStVGylUESkAHkWhkkA7kW+onGmjEMly7euHj+2oXz186cvnT29OUb1+89vP/84YPnjx6+AKOXUPLBC6gImPHwwYsH958x/KcAYNH8j2gAAM8YyFMqo2EkAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"LoggedIn\"\n        title=\"LoggedIn\"\n        src=\"/static/778f9ef9e4f7ce2740faf879b8c1615a/e5715/xwzztcogdtmnyfq4j5nc.png\"\n        srcset=\"/static/778f9ef9e4f7ce2740faf879b8c1615a/a6d36/xwzztcogdtmnyfq4j5nc.png 650w,\n/static/778f9ef9e4f7ce2740faf879b8c1615a/e5715/xwzztcogdtmnyfq4j5nc.png 768w,\n/static/778f9ef9e4f7ce2740faf879b8c1615a/29007/xwzztcogdtmnyfq4j5nc.png 1600w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<h2 id=\"fetching-user-profiles-from-access-tokens\" style=\"position:relative;\"><a href=\"#fetching-user-profiles-from-access-tokens\" aria-label=\"fetching user profiles from access tokens 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>Fetching User Profiles From Access Tokens</h2>\n<p>We also want to fetch user profiles from the <code>access token</code> given by LoginRadius. It comes in handy when we want to verify if a given access token is valid (or has expired) or just fetch information about the current user.</p>\n<p>Update the <code>login</code> route with the code below. We also added a <code>dashboard</code> route where we will redirect users after successful authentication.</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"python\" data-index=\"7\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk11\">@app.route</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;/login/&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">def</span><span class=\"mtk1\"> </span><span class=\"mtk11\">login</span><span class=\"mtk1\">():</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    access_token = request.args.get(</span><span class=\"mtk8\">&quot;token&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">if</span><span class=\"mtk1\"> access_token </span><span class=\"mtk4\">is</span><span class=\"mtk1\"> </span><span class=\"mtk4\">None</span><span class=\"mtk1\">:</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk3\"># redirect the user to our LoginRadius login URL if no access token is provided</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk15\">return</span><span class=\"mtk1\"> redirect(LR_AUTH_PAGE.format(</span><span class=\"mtk8\">&quot;login&quot;</span><span class=\"mtk1\">, request.base_url))</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk3\"># fetch the user profile details with their access tokens</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    result = loginradius.authentication.get_profile_by_access_token(</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        access_token)</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">if</span><span class=\"mtk1\"> result.get(</span><span class=\"mtk8\">&quot;ErrorCode&quot;</span><span class=\"mtk1\">) </span><span class=\"mtk4\">is</span><span class=\"mtk1\"> </span><span class=\"mtk4\">not</span><span class=\"mtk1\"> </span><span class=\"mtk4\">None</span><span class=\"mtk1\">:</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk3\"># redirect the user to our login URL if there was an error</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk15\">return</span><span class=\"mtk1\"> redirect(url_for(</span><span class=\"mtk8\">&quot;login&quot;</span><span class=\"mtk1\">))</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    session[</span><span class=\"mtk8\">&quot;user_acccess_token&quot;</span><span class=\"mtk1\">] = access_token</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">return</span><span class=\"mtk1\"> redirect(url_for(</span><span class=\"mtk8\">&quot;dashboard&quot;</span><span class=\"mtk1\">))</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk11\">@app.route</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;/dashboard/&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">def</span><span class=\"mtk1\"> </span><span class=\"mtk11\">dashboard</span><span class=\"mtk1\">():</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">return</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&quot;You have successfully logged in!&quot;</span></span></code></pre>\n<p>In the code above, we used the <code>authentication.get_profile_by_access_token</code> method from the LoginRadius SDK to fetch our user’s details. If the request was successful and the result does not contain an <code>ErrorCode</code> parameter, we save the access token in the user’s session and redirect them to the <code>dashboard</code> route. But if an error occurs somewhere, e.g., the access token is invalid/expired, we redirect the user back to the <code>login</code> route.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 25.384615384615383%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAFCAIAAADKYVtkAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAi0lEQVQY02OIMSyw0cowkUv10G300m/yNGh2UK2xVazUlvJXFLFTFHFQEsWJGFz1Uqy1Miw0kozUI001oi104+1MMh3Msu1M062NkoHIXDfeSCPaWDMGEzFcunjj4vlrF85fO3P60tnTl29cv/fowfOHD54/evgCjF4C2Q/uP8OKGP5TALBo/kc0AAAUs8dlLi9TOAAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"LoggedIn\"\n        title=\"LoggedIn\"\n        src=\"/static/f7ff18d73aa44304b1af09710f4dd5f2/e5715/f2p7ddnwin3yihucx2em.png\"\n        srcset=\"/static/f7ff18d73aa44304b1af09710f4dd5f2/a6d36/f2p7ddnwin3yihucx2em.png 650w,\n/static/f7ff18d73aa44304b1af09710f4dd5f2/e5715/f2p7ddnwin3yihucx2em.png 768w,\n/static/f7ff18d73aa44304b1af09710f4dd5f2/29007/f2p7ddnwin3yihucx2em.png 1600w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<p>Next, we want to add more functionality to the <code>dashboard</code> route. Instead of just displaying a dummy text, let it show the user information we fetched earlier. Update the <code>dashboard</code> route with the code below:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"python\" data-index=\"8\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk11\">@app.route</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;/dashboard/&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">def</span><span class=\"mtk1\"> </span><span class=\"mtk11\">dashboard</span><span class=\"mtk1\">():</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    access_token = session.get(</span><span class=\"mtk8\">&quot;user_acccess_token&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">if</span><span class=\"mtk1\"> access_token </span><span class=\"mtk4\">is</span><span class=\"mtk1\"> </span><span class=\"mtk4\">None</span><span class=\"mtk1\">:</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk15\">return</span><span class=\"mtk1\"> redirect(url_for(</span><span class=\"mtk8\">&quot;login&quot;</span><span class=\"mtk1\">))</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk3\"># fetch the user profile details with their access tokens</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    result = loginradius.authentication.get_profile_by_access_token(</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        access_token)</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">if</span><span class=\"mtk1\"> result.get(</span><span class=\"mtk8\">&quot;ErrorCode&quot;</span><span class=\"mtk1\">) </span><span class=\"mtk4\">is</span><span class=\"mtk1\"> </span><span class=\"mtk4\">not</span><span class=\"mtk1\"> </span><span class=\"mtk4\">None</span><span class=\"mtk1\">:</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk3\"># redirect the user to our login URL if there was an error</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk15\">return</span><span class=\"mtk1\"> redirect(url_for(</span><span class=\"mtk8\">&quot;login&quot;</span><span class=\"mtk1\">))</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">return</span><span class=\"mtk1\"> jsonify(result)</span></span></code></pre>\n<p>Here, we fetched the access token stored in the user’s session earlier, used it to get their details, and rendered the result.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 137.53846153846155%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAcCAIAAADuuAg3AAAACXBIWXMAAAsTAAALEwEAmpwYAAACr0lEQVQ4y5WUW08TQRTH91NgDN4iJVxKIEhtVS4VNIQHCYYoGBNDYkBERUh89MHEZx74TD5qTIgBQsKdXqDdW3dnOjuzM2fqLEtKS5Ctk5PJtJPfnjPn/M/RZnsWptIfuzteJ5rfvEitTiZXpgdWp/pXJ1MrI7FvT2Lfh1qX266PxJrSLU1DMWXX0lXTpruXx+JfUy2LfTdnUy3vk3fnH8QWlA20f37YutjftpyMzcXvPO+8PdF5a6L9xnhb87OqaYmumd6OmcGet8OJuUR8Ktn16n58uq/z5fDD+bHhpfHRL08HP42ml0aHAnuc+vCod67/3rvQtB9rud+bhfU/W79+ru3uZNS+sb6dz+nZTCFzpOwkly2qs9pDU1dV0wzL1k0buY6u66ZpWral60WMsecRyijnfuXfSyu6fM8UmEr1Q0oZ/ssYQwjJqKUVXJ4rAeWy9pOUUgVXopamI75xLDK28PzQ+RmMEY6GDcT3TWETGToPYRW2enY0fOLwzRPORF3YjLJGw97RxXZRhHyYM48Rj3nRsMr2vgmuJ72anKkiEUKiYQuLbElYZdAxCPjPsBW8awhWX6pGE6Zg9eBcSdR5bhC2sdgzBGbndToNW9X5NGxZbxfhstjWA89welcVCSo38GaHBHC2BBzOYc58YiDAXCIOrq8OYDOJ+UW4VA7CPrQEB1kDc+8YKQAsJgwmbMbzRFjsEvjQBNVYRQS1dUakoWxz5VlVy/FqtE1Z0BgyKmF5ix6YQHwJNXcCBBc82jNlvkPggkgqoiIJSAYRsAQoM6l6g4uzuga7L/wDxA8xOL70xBUi4RkbVEsrhVVhyqllGbIsgnbx4aphsGOIrQLPOwEfjoRAJLgBkZg4GICIBpNEiTQUWqDtMNsRMPKPLHApXNpVajaos+u6pcvWX24d58OOTRQqAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"LoggedIn\"\n        title=\"LoggedIn\"\n        src=\"/static/18bb6535f77c2607bb7398b12627fdad/e5715/1zsvbg3rk013zlbpxx2u.png\"\n        srcset=\"/static/18bb6535f77c2607bb7398b12627fdad/a6d36/1zsvbg3rk013zlbpxx2u.png 650w,\n/static/18bb6535f77c2607bb7398b12627fdad/e5715/1zsvbg3rk013zlbpxx2u.png 768w,\n/static/18bb6535f77c2607bb7398b12627fdad/05fb0/1zsvbg3rk013zlbpxx2u.png 1138w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<h3 id=\"invalidating-access-tokens-user-logout\" style=\"position:relative;\"><a href=\"#invalidating-access-tokens-user-logout\" aria-label=\"invalidating access tokens user logout 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>Invalidating Access Tokens (User Logout)</h3>\n<p>Invalidating access tokens means rendering particular access tokens useless and unusable. It comes in handy when we log out users. The LoginRadius SDK provides an <code>auth_in_validate_access_token</code> method that takes in an access token to be invalidated.</p>\n<p>To add this to our server, create a <code>logout</code> route with the code below:</p>\n<pre class=\"grvsc-container dark-default-dark\" data-language=\"python\" data-index=\"9\"><code class=\"grvsc-code\"><span class=\"grvsc-line\"><span class=\"mtk11\">@app.route</span><span class=\"mtk1\">(</span><span class=\"mtk8\">&quot;/logout/&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk4\">def</span><span class=\"mtk1\"> </span><span class=\"mtk11\">logout</span><span class=\"mtk1\">():</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    access_token = session.get(</span><span class=\"mtk8\">&quot;user_acccess_token&quot;</span><span class=\"mtk1\">)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">if</span><span class=\"mtk1\"> access_token </span><span class=\"mtk4\">is</span><span class=\"mtk1\"> </span><span class=\"mtk4\">None</span><span class=\"mtk1\">:</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">        </span><span class=\"mtk15\">return</span><span class=\"mtk1\"> redirect(url_for(</span><span class=\"mtk8\">&quot;login&quot;</span><span class=\"mtk1\">))</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk3\"># invalidate the access token with LoginRadius API</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    loginradius.authentication.auth_in_validate_access_token(access_token)</span></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    session.clear()</span></span>\n<span class=\"grvsc-line\"></span>\n<span class=\"grvsc-line\"><span class=\"mtk1\">    </span><span class=\"mtk15\">return</span><span class=\"mtk1\"> </span><span class=\"mtk8\">&quot;You have successfully logged out!&quot;</span></span></code></pre>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 768px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 36.92307692307692%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAHCAIAAACHqfpvAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA30lEQVQY02MoMCtMcCk30Uu3ks8ItZoQZjUh2mFKuM1EN81mJ5V6N/VWK6UMDSknVQlHVQkHNUlHNUknOGJwUEoylszWk0jUlohWFwtRFwsFozBd2Tg9+URjlVQj1XgN2QB1IJIJUBL3URD1giOGCL/iSP+y6ICK2KDqYO+CEJ/CUN+iEJ+i+Ij6xOjmlLjW9MSO5JjW5GgQig2tjwqugyOG169fvXr18u3bNy9evHj58uXz58+fPHny/v37/0QAhm/fv//79+/vn78I8OcvEvcfGGEHDD9+/PhPLqBIMwCZ9B/QHMr8mgAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Log Out\"\n        title=\"Log Out\"\n        src=\"/static/7ee08aa463b99115f34baf4e3a011bcf/e5715/xyvodwpjtxjrjgxoffx5.png\"\n        srcset=\"/static/7ee08aa463b99115f34baf4e3a011bcf/a6d36/xyvodwpjtxjrjgxoffx5.png 650w,\n/static/7ee08aa463b99115f34baf4e3a011bcf/e5715/xyvodwpjtxjrjgxoffx5.png 768w,\n/static/7ee08aa463b99115f34baf4e3a011bcf/05fb0/xyvodwpjtxjrjgxoffx5.png 1138w\"\n        sizes=\"(max-width: 768px) 100vw, 768px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n      />\n    </span></p>\n<h2 id=\"conclusion\" style=\"position:relative;\"><a href=\"#conclusion\" aria-label=\"conclusion 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>Conclusion</h2>\n<p>This article taught us about user authentication, user identity management, and implementing it correctly. In addition, we saw how easy it is to integrate LoginRadius services into a Python application to ease the implementation of authentication and user identity management.</p>\n<p>The source code of the demo application is available as a <a href=\"https://gist.github.com/LordGhostX/01e9330dc4533a992a481fcd58fdd115\">GitHub gist</a>. You can learn more about the LoginRadius Python SDK features from the <a href=\"https://www.loginradius.com/developers/\">official documentation</a>.</p>\n<style class=\"grvsc-styles\">\n  .grvsc-container {\n    overflow: auto;\n    -webkit-overflow-scrolling: touch;\n    padding-top: 1rem;\n    padding-top: var(--grvsc-padding-top, var(--grvsc-padding-v, 1rem));\n    padding-bottom: 1rem;\n    padding-bottom: var(--grvsc-padding-bottom, var(--grvsc-padding-v, 1rem));\n    border-radius: 8px;\n    border-radius: var(--grvsc-border-radius, 8px);\n    font-feature-settings: normal;\n  }\n  \n  .grvsc-code {\n    display: inline-block;\n    min-width: 100%;\n  }\n  \n  .grvsc-line {\n    display: inline-block;\n    box-sizing: border-box;\n    width: 100%;\n    padding-left: 1.5rem;\n    padding-left: var(--grvsc-padding-left, var(--grvsc-padding-h, 1.5rem));\n    padding-right: 1.5rem;\n    padding-right: var(--grvsc-padding-right, var(--grvsc-padding-h, 1.5rem));\n  }\n  \n  .grvsc-line-highlighted {\n    background-color: var(--grvsc-line-highlighted-background-color, transparent);\n    box-shadow: inset var(--grvsc-line-highlighted-border-width, 4px) 0 0 0 var(--grvsc-line-highlighted-border-color, transparent);\n  }\n  \n  .dark-default-dark {\n    background-color: #1E1E1E;\n    color: #D4D4D4;\n  }\n  .dark-default-dark .mtk1 { color: #D4D4D4; }\n  .dark-default-dark .mtk15 { color: #C586C0; }\n  .dark-default-dark .mtk12 { color: #9CDCFE; }\n  .dark-default-dark .mtk8 { color: #CE9178; }\n  .dark-default-dark .mtk11 { color: #DCDCAA; }\n  .dark-default-dark .mtk4 { color: #569CD6; }\n  .dark-default-dark .mtk3 { color: #6A9955; }\n</style>","headings":[{"value":"Introduction","depth":2},{"value":"What Is User Authentication?","depth":3},{"value":"What Is User Identity?","depth":3},{"value":"What Is an Identity Provider?","depth":3},{"value":"What Is Authentication in Python?","depth":2},{"value":"Getting Started with LoginRadius","depth":2},{"value":"What Is LoginRadius?","depth":3},{"value":"Benefits of Using LoginRadius","depth":3},{"value":"Acquiring LoginRadius API Credentials","depth":3},{"value":"Whitelisting Your Domains","depth":3},{"value":"Installing LoginRadius Python SDK","depth":3},{"value":"Setting up Our Flask Server","depth":3},{"value":"Initializing the LoginRadius SDK","depth":3},{"value":"Setting up User Registration","depth":2},{"value":"Authenticating Registered Users (User Login)","depth":3},{"value":"Fetching User Profiles From Access Tokens","depth":2},{"value":"Invalidating Access Tokens (User Logout)","depth":3},{"value":"Conclusion","depth":2}],"fields":{"slug":"/engineering/guest-post/user-authentication-in-python/"},"frontmatter":{"metatitle":null,"metadescription":null,"description":"Learn about user authentication, user identity management, and implementing it correctly into a Python application using LoginRadius.","title":"Implementing User Authentication in a Python Application","canonical":null,"date":"July 07, 2021","updated_date":null,"tags":["Python","Authentication","Flask"],"coverImage":{"childImageSharp":{"fluid":{"aspectRatio":1.5037593984962405,"src":"/static/9c74b4b9c19fc76911f54b82e0cceb74/701ee/coverImage.jpg","srcSet":"/static/9c74b4b9c19fc76911f54b82e0cceb74/3dcee/coverImage.jpg 200w,\n/static/9c74b4b9c19fc76911f54b82e0cceb74/ae6ae/coverImage.jpg 400w,\n/static/9c74b4b9c19fc76911f54b82e0cceb74/701ee/coverImage.jpg 800w,\n/static/9c74b4b9c19fc76911f54b82e0cceb74/8c3c2/coverImage.jpg 1200w","sizes":"(max-width: 800px) 100vw, 800px"}}},"author":{"id":"Solomon Esenyi","github":"LordGhostX","bio":"Python Developer and Technical Writer with a passion for open-source, cryptography, and serverless technologies.","avatar":null}}}},"pageContext":{"id":"b187fd34-4497-550b-af19-25792fd842f8","fields__slug":"/engineering/guest-post/user-authentication-in-python/","__params":{"fields__slug":"engineering"}}},"staticQueryHashes":["1171199041","1384082988","1711371485","1753898100","2100481360","229320306","23180105","528864852"]}