Abhishek Thakur
commited on
Commit
·
4046997
1
Parent(s):
ef69751
auth
Browse files
competitions/oauth.py
CHANGED
@@ -22,9 +22,6 @@ OPENID_PROVIDER_URL = os.environ.get("OPENID_PROVIDER_URL")
|
|
22 |
|
23 |
|
24 |
def attach_oauth(app: fastapi.FastAPI):
|
25 |
-
# Add `/login/huggingface`, `/login/callback` and `/logout` routes to enable OAuth in the Gradio app.
|
26 |
-
# If the app is running in a Space, OAuth is enabled normally. Otherwise, we mock the "real" routes to make the
|
27 |
-
# user log in with a fake user profile - without any calls to hf.co.
|
28 |
if os.environ.get("SPACE_ID") is not None and int(os.environ.get("USE_OAUTH", 0)) == 1:
|
29 |
_add_oauth_routes(app)
|
30 |
else:
|
@@ -39,7 +36,7 @@ def attach_oauth(app: fastapi.FastAPI):
|
|
39 |
SessionMiddleware,
|
40 |
secret_key=hashlib.sha256(session_secret.encode()).hexdigest(),
|
41 |
same_site="none",
|
42 |
-
|
43 |
)
|
44 |
|
45 |
|
@@ -74,12 +71,12 @@ def _add_oauth_routes(app: fastapi.FastAPI) -> None:
|
|
74 |
async def oauth_login(request: fastapi.Request):
|
75 |
"""Endpoint that redirects to HF OAuth page."""
|
76 |
# Define target (where to redirect after login)
|
77 |
-
redirect_uri = _generate_redirect_uri(request)
|
78 |
-
|
79 |
return await oauth.huggingface.authorize_redirect(request, redirect_uri) # type: ignore
|
80 |
|
81 |
-
@app.get("/
|
82 |
-
async def
|
83 |
"""Endpoint that handles the OAuth callback."""
|
84 |
# oauth_info = await oauth.huggingface.authorize_access_token(request) # type: ignore
|
85 |
try:
|
|
|
22 |
|
23 |
|
24 |
def attach_oauth(app: fastapi.FastAPI):
|
|
|
|
|
|
|
25 |
if os.environ.get("SPACE_ID") is not None and int(os.environ.get("USE_OAUTH", 0)) == 1:
|
26 |
_add_oauth_routes(app)
|
27 |
else:
|
|
|
36 |
SessionMiddleware,
|
37 |
secret_key=hashlib.sha256(session_secret.encode()).hexdigest(),
|
38 |
same_site="none",
|
39 |
+
https_only=True,
|
40 |
)
|
41 |
|
42 |
|
|
|
71 |
async def oauth_login(request: fastapi.Request):
|
72 |
"""Endpoint that redirects to HF OAuth page."""
|
73 |
# Define target (where to redirect after login)
|
74 |
+
# redirect_uri = _generate_redirect_uri(request)
|
75 |
+
redirect_uri = request.url_for("auth")
|
76 |
return await oauth.huggingface.authorize_redirect(request, redirect_uri) # type: ignore
|
77 |
|
78 |
+
@app.get("/auth")
|
79 |
+
async def auth(request: fastapi.Request) -> RedirectResponse:
|
80 |
"""Endpoint that handles the OAuth callback."""
|
81 |
# oauth_info = await oauth.huggingface.authorize_access_token(request) # type: ignore
|
82 |
try:
|
competitions/templates/index.html
CHANGED
@@ -388,7 +388,7 @@
|
|
388 |
class="mt-1 block w-full border border-gray-300 px-3 py-1.5 bg-white rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
|
389 |
</li>
|
390 |
<li id="loginButton" style="display: none;">
|
391 |
-
<a href="/login/huggingface"
|
392 |
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">Login with Hugging
|
393 |
Face</a>
|
394 |
</li>
|
@@ -468,13 +468,6 @@
|
|
468 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/flowbite/2.2.1/flowbite.min.js"></script>
|
469 |
</body>
|
470 |
|
471 |
-
<script>
|
472 |
-
document.getElementById('huggingFaceLogin').addEventListener('click', function (event) {
|
473 |
-
event.preventDefault(); // Prevent the default link behavior
|
474 |
-
window.parent.location.href = this.getAttribute('href'); // Open link in parent window/tab
|
475 |
-
});
|
476 |
-
</script>
|
477 |
-
|
478 |
<script>
|
479 |
document.addEventListener('DOMContentLoaded', function () {
|
480 |
document.querySelector('.confirm').addEventListener('click', function (event) {
|
|
|
388 |
class="mt-1 block w-full border border-gray-300 px-3 py-1.5 bg-white rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500">
|
389 |
</li>
|
390 |
<li id="loginButton" style="display: none;">
|
391 |
+
<a href="/login/huggingface" target="_blank"
|
392 |
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">Login with Hugging
|
393 |
Face</a>
|
394 |
</li>
|
|
|
468 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/flowbite/2.2.1/flowbite.min.js"></script>
|
469 |
</body>
|
470 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
471 |
<script>
|
472 |
document.addEventListener('DOMContentLoaded', function () {
|
473 |
document.querySelector('.confirm').addEventListener('click', function (event) {
|