diff --git a/reddash/app/api/routes.py b/reddash/app/api/routes.py index 26a95c35..726ceda2 100644 --- a/reddash/app/api/routes.py +++ b/reddash/app/api/routes.py @@ -611,3 +611,35 @@ def third_party_spotify_callback(): except Exception as e: app.progress.print("".join(traceback.format_exception(type(e), e, e.__traceback__))) return render_template("third_party/spotify.html", context="2", msg=str(e)) + + +@blueprint.route("/third_party/callback/") +def third_party_oauth_callback(provider): + args = request.args.copy() + args["provider"] = provider + if not session.get("id"): + session["login_redirect"] = { + "route": f"api_blueprint.third_party_oauth_callback", + "kwargs": args, + } + return redirect(url_for("base_blueprint.login")) + args["url"] = request.url + try: + requeststr = { + "jsonrpc": "2.0", + "id": 0, + "method": "DASHBOARDRPC_OAUTH__OAUTH_RECEIVE", + "params": [str(g.id), args], + } + with app.lock: + result = get_result(app, requeststr).json + if result["status"] == 0: + return render_template("third_party/oauth.html", context="2", msg=result["message"]) + if result["data"]["status"] == 0: + return render_template( + "third_party/oauth.html", context="3", msg=result["data"]["message"] + ) + return render_template("third_party/oauth.html", context="1", msg="") + except Exception as e: + app.progress.print("".join(traceback.format_exception(type(e), e, e.__traceback__))) + return render_template("third_party/oauth.html", context="2", msg=str(e)) diff --git a/reddash/app/dashboard/templates/third_party/oauth.html b/reddash/app/dashboard/templates/third_party/oauth.html new file mode 100644 index 00000000..05f81977 --- /dev/null +++ b/reddash/app/dashboard/templates/third_party/oauth.html @@ -0,0 +1,45 @@ +{% extends "base-site.html" %} + +{% block title %} {{ _('Third Party OAuth') }} {% endblock %} + + +{% block stylesheets %}{% endblock stylesheets %} + +{% block content %} + +
+
+
+
+
{{ _('OAuth Redirect') }}
+
+
+
+ {% if context == '1' %} +
{{ _("Successfully connected your account. You may now close this tab.") }} +
+ {% else %} + {% if context == '2' %} +
{{ _("We had trouble contacting the bot to authenticate: {message}").format(message=msg) }} +
+ {% else %} +
{{ _("We failed to authenticate you: {message}").format(message=msg) }} +
+ {% endif %} + {% endif %} +
+
+
+
+ +
+
+
+ +{% endblock content %} + + +{% block javascripts %} +{% endblock javascripts %} \ No newline at end of file