Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
devxpy committed Mar 7, 2025
2 parents 7c36f2a + 9aaabb8 commit c4671c7
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 5 deletions.
20 changes: 15 additions & 5 deletions routers/onedrive_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from bots.models import SavedRun
from daras_ai_v2 import settings
from daras_ai_v2.exceptions import raise_for_status
from daras_ai_v2.settings import templates
from routers.custom_api_router import CustomAPIRouter

app = CustomAPIRouter()
Expand All @@ -26,12 +27,21 @@ def onedrive_connect_redirect(request: Request):
sr = load_sr_from_state(request)
code = request.query_params.get("code")
if not code:
error = request.query_params.get("error")
error_description = request.query_params.get("error_description")
return HTMLResponse(
f"Authorization code missing! {error} : {error_description}",
status_code=400,
error = request.query_params.get("error", "Authentication failed")
error_description = request.query_params.get(
"error_description", "An error occurred during authentication."
)
sr_id = json.loads(request.query_params.get("state") or "{}").get("sr_id")
redirect_url = sr.get_app_url()

context = {
"request": request,
"error": error,
"error_description": error_description,
"redirect_url": redirect_url,
"retry_url": generate_onedrive_auth_url(sr_id=sr_id),
}
return templates.TemplateResponse("authorization_error.html", context=context)

user_access_token, user_refresh_token = _get_access_token_from_code(code)
user_display_name = _get_user_display_name(user_access_token)
Expand Down
61 changes: 61 additions & 0 deletions templates/authorization_error.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{% extends 'base.html' %}

{% block title %}Authorization Error{% endblock title %}

{% block content %}
<div style="text-align: center; margin: 2rem 0;">

<h1>Authorization Error</h1>
<div class="container border p-2">
<pre class="text-danger">{{ error }}</pre>
<pre class="text-center mx-4 mb-4 bg-light">
{{ error_description or "An error occurred during authentication." }}
</pre>
</div>

<div style="margin-top: 2rem; display: flex; gap: 2rem; justify-content: center;">
<a
href="{{ redirect_url | default('/') }}"style="
display: inline-block;
text-decoration: none;
padding: 12px;
background-color: #fff;
color: #000;
border-radius: 6px;
transition: all 0.1s ease;"
onmouseover="
this.style.borderColor='#000';
this.style.color='#000';
this.style.backgroundColor='#FEF1F5'"
onmouseout="
this.style.borderColor='#c9c9c9';
this.style.color='#c9c9c9';
this.style.backgroundColor='#FFF';"
> Back to Run
</a>
<a
href="{{ retry_url }}"
style="
display: inline-block;
text-decoration: none;
padding: 12px;
border: 1px solid #000;
background-color: #000;
color: #fff;
border-radius: 6px;
transition: all 0.1s ease;"
onmouseover="
this.style.backgroundColor='#3EFFEA';
this.style.color='#000';
this.style.borderColor='#000';"
onmouseout="
this.style.backgroundColor='#000';
this.style.color='#fff';
this.style.borderColor='#000';"

> Retry Authorization
</a>
</div>
</div>

{% endblock content %}

0 comments on commit c4671c7

Please sign in to comment.