-
Notifications
You must be signed in to change notification settings - Fork 0
feat install decap #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat install decap #192
Changes from 20 commits
7193d25
9a88690
5f325bc
dc930ac
50300e0
53db915
72eae90
f8c5e67
17a84b0
c101936
233a6db
e7ecf28
6bcf76a
378639b
8963e47
3b3fd6a
df88c88
c73a7cc
967a21b
63c0b52
9746e34
c7cfbdf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| [submodule "static/content"] | ||
| path = static/content | ||
| url = git@github.com:TelesCoop/iarbre-showcase-content.git | ||
| branch = main |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # Sveltia CMS / Decap CMS Github Oauth Django Application | ||
|
|
||
| Add Github Authentication to DecapCMS through yor Django Application. | ||
|
|
||
| ## Getting Started | ||
|
|
||
| ### 1. Create and register your Github OAuth Application | ||
|
|
||
| Please read [official doc](https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/creating-an-oauth-app). | ||
|
|
||
| Authorization callback URL should be : | ||
|
|
||
| ``` | ||
| https://<your application url>/callback | ||
| ``` | ||
|
|
||
| Copy-paste application id and client secret. | ||
|
|
||
| ### 2. Install Decap CMS in your Django Project | ||
|
|
||
| #### `settings.py` : | ||
|
|
||
| - Install application : | ||
|
|
||
| ```py | ||
| INSTALLED_APPS = [ | ||
| ..., | ||
| "decapcms_auth", | ||
| ] | ||
| ``` | ||
|
|
||
| - Set up required variables : | ||
|
|
||
| ```py | ||
|
|
||
| DECAP_CMS_AUTH = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C'est pas très clair pour moi la manière dont on doit récupérer ce token ? Est-ce une valeur qu'on définit nous-mêmes ? À récupérer quelque part ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. J’ai ajouté plus de docs. |
||
| "OAUTH_CLIENT_ID": "<public application client id>", | ||
| "OAUTH_CLIENT_SECRET": "<private application client secret>" | ||
| "SCOPE": "repo,user" | ||
| } | ||
| ``` | ||
|
|
||
| ⚠️ `OAUTH_CLIENT_SECRET` should not be publicly disclosed. | ||
|
|
||
| - Define this environment variable: | ||
|
|
||
| ```py | ||
| os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1" | ||
| ``` | ||
|
|
||
| #### `urls.py` | ||
|
|
||
| Include the Decap CMS urls : | ||
|
|
||
| ```py | ||
|
|
||
| from decapcms_auth import urls as decapcmsauth_urls | ||
| ... | ||
| urlpatterns = [ | ||
| ... | ||
| path("cms/", include(decapcmsauth_urls)), | ||
| ... | ||
| ] | ||
| ``` | ||
|
|
||
| ### 3. In your Decap CMS config.yml | ||
|
|
||
| ```yml | ||
| backend: | ||
| name: github | ||
| branch: main | ||
| repo: <your repo> | ||
| base_url: <base url of your application> | ||
| auth_endpoint: /cms/auth # /cms | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| from django.apps import AppConfig | ||
|
|
||
|
|
||
| class DecapcmsAuthConfig(AppConfig): | ||
| default_auto_field = "django.db.models.BigAutoField" | ||
| name = "decapcms_auth" | ||
| verbose_name = "DecapCMS auth config" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <html> | ||
| <body> | ||
| <script> | ||
| (function () { | ||
| function recieveMessage(e) { | ||
| console.log("recieveMessage %o", e); | ||
| // send message to main window with da app | ||
| const provider = "github" | ||
| const state = "success" | ||
| window.opener.postMessage( | ||
| `authorization:${provider}:${state}:${JSON.stringify({{content | safe}})}`, | ||
| e.origin, | ||
| ); | ||
| } | ||
| window.addEventListener("message", recieveMessage, false); | ||
| // Start handshare with parent | ||
| console.log("Sending message: %o", "github"); | ||
| window.opener.postMessage("authorizing:github", "*"); | ||
| })(); | ||
| </script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| from django.urls import path | ||
| from rest_framework import routers | ||
|
|
||
| from .views import callback, auth | ||
|
|
||
| router = routers.DefaultRouter() | ||
|
|
||
| urlpatterns = [ | ||
| path("auth/", auth), | ||
| path("callback/", callback), | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| from requests_oauthlib import OAuth2Session | ||
| from django.conf import settings | ||
| from django.shortcuts import redirect, render | ||
| from django.http import HttpResponseBadRequest | ||
|
|
||
| AUTHORIZATION_BASE_URL = "https://github.com/login/oauth/authorize" | ||
| TOKEN_URL = "https://github.com/login/oauth/access_token" | ||
| CLIENT_ID = settings.DECAP_CMS_AUTH["OAUTH_CLIENT_ID"] | ||
| CLIENT_SECRET = settings.DECAP_CMS_AUTH["OAUTH_CLIENT_SECRET"] | ||
| SCOPE = settings.DECAP_CMS_AUTH["SCOPE"] | ||
|
|
||
|
|
||
| def auth(request): | ||
| """Redirect to Github auth""" | ||
| github = OAuth2Session(client_id=CLIENT_ID, scope=SCOPE) | ||
| authorization_url, _ = github.authorization_url(AUTHORIZATION_BASE_URL) | ||
| return redirect(authorization_url) | ||
|
|
||
|
|
||
| def callback(request): | ||
| """Retrieve access token""" | ||
| state = request.GET.get("state", "") | ||
| try: | ||
| github = OAuth2Session(CLIENT_ID, state=state, scope=SCOPE) | ||
| token = github.fetch_token( | ||
| TOKEN_URL, | ||
| client_secret=CLIENT_SECRET, | ||
| authorization_response=request.get_full_path(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je suis étonné du lint pour cette ligne
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. J’ai relancé sur l’intégralité du code et ça passe pour moi avec la configuration actuelle. |
||
| ) | ||
| content = {"token": token.get("access_token", ""), "provider": "github"} | ||
| return render(request, "decapcms_auth/callback.html", {"content": content}) | ||
|
|
||
| except BaseException: | ||
| return HttpResponseBadRequest() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,35 @@ | ||
| $ANSIBLE_VAULT;1.1;AES256 | ||
| 37643939363936323039323662313262616665376532366639366234333833373032323830323562 | ||
| 3161633961646239663933343933333338326466626435610a646537393039373737623465356662 | ||
| 62333566626533633136383535373634373232613133633330376336303331316139383631376162 | ||
| 3633653564613939390a376665623932366264333865383931623361333764313664326637343566 | ||
| 35393434636239333766353162303630326237303631643534363765653538643162373632316564 | ||
| 34373136333933373934393533633564656633323838363261333065653066386137353936646666 | ||
| 32306530383865303736383762636364306432626563303837663566316430343465636436383531 | ||
| 64656136666635633136376636323164303535643339303862633037623966373635333238306237 | ||
| 32393732633237363736333134636161323163333439626331663461633437646534356635633230 | ||
| 64383531633963613161643063343837326665656239633836613361303732666136616365646562 | ||
| 62613030633961643666643139626632623036653532626666323839303038633435383766643962 | ||
| 30666565633137316361656639613263303532656461393066643939333835643037323336386664 | ||
| 64303835313961313831363461313934396133303136636633613832626439343762633131353164 | ||
| 62343263663461643861306431393866376532326233353136353963376161316463363364656230 | ||
| 62316239643561376636323461636136313762376665356433323934366265313935363063633764 | ||
| 63316161323365313032363432653763646439386365656239383566633063363835323039366139 | ||
| 66383432323364333837373830643439343361646365353333303466343330323031343232333636 | ||
| 36633430623637366539393730663835386466316537613135663537353733386631396564653066 | ||
| 30633534323965346464663337623664333466313361343531373131393666653662346530396134 | ||
| 62353932646434666566336463666337643330376630303466626561366263633164383162663563 | ||
| 37613631376230633562633565616134636237643565323334643263333431343562646532663130 | ||
| 36393337366433623330343765356635373033363335353933333166383465323430613665326430 | ||
| 65383862346462373930323938303032316634623961356565613039643237313063333331386162 | ||
| 37613462633566326433366161343766316637323065386532333236316637366462336333623932 | ||
| 34323538643238383665393463646636613036363332353362646237386232353932346332306331 | ||
| 65613534313837376232373632313438653037306630346638616433373133353534306430616234 | ||
| 33633339376333356266663634653765323039623730366635373632636333363966353139636532 | ||
| 63363339666337633138 | ||
| 62393734386563303834643531386666653633303134393830663666656234373662323464346432 | ||
| 3534343536613637356431393464363662653631306161390a646162343535653635383263653838 | ||
| 32326132636132336662356230356531383733313061313737643736633931303637633566353537 | ||
| 3433343439623439350a313131393861386336333965366461336230616462323630306432356463 | ||
| 65613433323064623739633832323238376536323038656235313237623437363164323466633832 | ||
| 61383435656237343438373163316139346136346436346131333439303534393964666631363964 | ||
| 37313661383230306363373065663132363336653962363064656435373439333964336632306239 | ||
| 64363665376537313233363234656238636236306166393838663863323930356665643864636562 | ||
| 62626466333863333866633034616662346330613461303866346432623834316238346537383265 | ||
| 31373961326435313736643464353766316162396566363462393431366133613965366430336338 | ||
| 37653063303132643330663938346533653065346131336164323831623030326631353464373130 | ||
| 35303062366261393362316434326665643263383133356131313162343863656435313063663836 | ||
| 39663235356336643432336663396436373165633463616232303061336239633739643433303866 | ||
| 66353737373832383962626232363336643630343036366336626234323037393037363537326365 | ||
| 35343232396436396633623966323234353533396237376235396635306264313339653331346338 | ||
| 65326131393430316362656662653231393630636266653931316364333938633335633235636136 | ||
| 33616336313831626163356337303666323132396434386566376161366563663666613537383062 | ||
| 32653266656163306437616530336461653164383537663663313739633761366361663462653538 | ||
| 36363433323064616533623339313262653332656130323766613132636232653435643065663735 | ||
| 32656137333366313832346536623130666265343566653134663038636232646461373236396661 | ||
| 37613561343831633734373063343564626234616235303266393664303631306464613061643530 | ||
| 62396635353365643631623862323132396636303863336464353862366537653234623265356663 | ||
| 30336539393662383765653132643431303938373062373937623261393361393466373136393437 | ||
| 32383365343161303937346539333264353236303737323962646631653433316566623061633831 | ||
| 63616364376438616238336262666165353638303065383765393035383537353236353039633662 | ||
| 35353063663037633037643731663864373530366638373833636365366338316534636230326539 | ||
| 32376533653232653930373335393564616332393138656335376633623762383135613530626131 | ||
| 32643863306434303534373335666437303963626238636363663136643633353463373031323362 | ||
| 64336535393761353831346635656530633330353234653762326438623437646234663530616336 | ||
| 64633161393239356231663064353737313135373135393066303638306530373136346636363264 | ||
| 38663261363062623736623664633439626132393030623839666237633363633431333265363030 | ||
| 37343232326639306565333539373165343965616664323634663135343633633138393262376362 | ||
| 66303365303536626166333333613332353934366365346261656634373937653439363334633939 | ||
| 3964363465313663373064393566396234356439373131653463 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,3 +6,4 @@ server_uris_passed_to_backend: | |
| - api | ||
| - backup | ||
| - hijack | ||
| - cms | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je ne suis pas sur de comprendre pourquoi on voudrait mettre à jour le site statique quand on merge sur
main?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ces lignes spécifiquement permettent d’avoir un site statique à jour quand on est sur une branche. C’est utile parfois, en l'occurrence pour cette MR ça m’était indispensable de pouvoir disposer d’un environnement "feature".
On pourrait éventuellement vouloir désactiver cet environnement (ou le front ou le back) si notre PR n’y touche pas. Mais ça fait un peu de travail et de la complexité pour je pense, pas grand chose.