|
20 | 20 | from django.http import Http404, StreamingHttpResponse
|
21 | 21 | from django.urls import reverse
|
22 | 22 | from django.utils.functional import cached_property
|
| 23 | +from django.shortcuts import redirect |
23 | 24 | from django.utils.text import capfirst, slugify
|
24 | 25 | from django.utils.translation import gettext_lazy as _
|
25 | 26 |
|
@@ -2072,3 +2073,42 @@ def _load_theme_customization(self):
|
2072 | 2073 | )
|
2073 | 2074 |
|
2074 | 2075 | return theme_customization
|
| 2076 | + |
| 2077 | +notion_client_id = "206d872b-594c-80de-94ff-003760c352e4" |
| 2078 | +notion_client_secret = "XXX" |
| 2079 | +notion_redirect_uri = "https://emersion.fr/notion-redirect" |
| 2080 | + |
| 2081 | +@drf.decorators.api_view() |
| 2082 | +def notion_import_redirect(request): |
| 2083 | + query = urlencode({ |
| 2084 | + "client_id": notion_client_id, |
| 2085 | + "response_type": "code", |
| 2086 | + "owner": "user", |
| 2087 | + "redirect_uri": notion_redirect_uri, |
| 2088 | + }) |
| 2089 | + return redirect("https://api.notion.com/v1/oauth/authorize?" + query) |
| 2090 | + |
| 2091 | +@drf.decorators.api_view() |
| 2092 | +def notion_import_callback(request): |
| 2093 | + code = request.GET.get("code") |
| 2094 | + resp = requests.post( |
| 2095 | + "https://api.notion.com/v1/oauth/token", |
| 2096 | + auth=requests.auth.HTTPBasicAuth(notion_client_id, notion_client_secret), |
| 2097 | + headers={"Accept": "application/json"}, |
| 2098 | + data={ |
| 2099 | + "grant_type": "authorization_code", |
| 2100 | + "code": code, |
| 2101 | + "redirect_uri": notion_redirect_uri, |
| 2102 | + }, |
| 2103 | + ) |
| 2104 | + resp.raise_for_status() |
| 2105 | + data = resp.json() |
| 2106 | + request.session["notion_token"] = data["access_token"] |
| 2107 | + return redirect("/api/v1.0/notion_import/run") |
| 2108 | + |
| 2109 | +#@drf.decorators.api_view(["POST"]) |
| 2110 | +@drf.decorators.api_view() |
| 2111 | +def notion_import_run(request): |
| 2112 | + if "notion_token" not in request.session: |
| 2113 | + raise drf.exceptions.PermissionDenied() |
| 2114 | + return drf.response.Response({"sava": "oui et toi ?"}) |
0 commit comments