CoolFace
Apppublic

awacke1/Authenticate-client-side-oauth

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
index.html44 linesDownload Raw Back to root
1<!DOCTYPE html>2<html>3	<head>4		<meta charset="utf-8" />5		<meta name="viewport" content="width=device-width" />6		<title>My static Space</title>7		<link rel="stylesheet" href="style.css" />8        <script src="https://unpkg.com/es-module-shims@1.7.0/dist/es-module-shims.js"></script>9		<script type="importmap">10			{11				"imports": {12					"@huggingface/hub": "https://cdn.jsdelivr.net/npm/@huggingface/hub@0.13.0/+esm"13				}14			}15		</script>16	</head>17	<body>18      <div class="card">19        <h1>OAuth in a static Space</h1>20        <p>Checkout the <a href="https://huggingface.co/spaces/huggingfacejs/client-side-oauth/blob/main/index.html" target="_blank">index.html</a> file to see the few lines of code21        enabling this space</p>22        <p>After clicking "Signin with HF", you will be redirected to this space and the access token + user info will be displayed.</p>23      </div>24      <img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/sign-in-with-huggingface-xl-dark.svg" alt="Sign in with Hugging Face" style="cursor: pointer; display: none;" id="signin">25      <pre>26        27      </pre>28      <script type="module">29        import { oauthLoginUrl, oauthHandleRedirectIfPresent } from "@huggingface/hub";30 31        const oauthResult = await oauthHandleRedirectIfPresent();32 33        if (oauthResult) {34          document.querySelector("pre").textContent = JSON.stringify(oauthResult, null, 2);35        } else {36          document.getElementById("signin").style.removeProperty("display");37          document.getElementById("signin").onclick = async function() {38            window.location.href = await oauthLoginUrl();39          }40        }41      </script>42	</body>43</html>44