From 22728403ee10c047c3c6fa6f93f1412fdd304032 Mon Sep 17 00:00:00 2001 From: Jakub K Date: Mon, 22 Jan 2024 21:44:59 +0100 Subject: [PATCH] =?UTF-8?q?przekazanie=20do=20sekret=C3=B3w=20do=20env=20-?= =?UTF-8?q?=20test=20only?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 3 ++- izaac/settings.py | 4 ++++ jobposting/views.py | 18 ++++++++++++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5116506..e798101 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,8 @@ WORKDIR /usr/scr/app ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 - +ENV REACT_CLIENT_ID="aNTgOypzDqw4BC3QDIAl7OlTUSBEoHKKWCM0LuRG" +ENV REACT_CLIENT_SECRET="W21lvouisPlDKJCKH2QvL0tI5PuQjVlmKzOSqnDTGQmKruQuNl38WyrBzCc2b4A7FhuOAxaLTe5TM8myqvibkglRRTAtxeh5UyM8HsI6ww28ARTK6hdH9xSk5l1JnKVB" RUN pip install --upgrade pip COPY ./requirements.txt . RUN pip install -r requirements.txt diff --git a/izaac/settings.py b/izaac/settings.py index c0a9d69..1bdb178 100644 --- a/izaac/settings.py +++ b/izaac/settings.py @@ -17,6 +17,10 @@ import os # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent +REACT_CLIENT_ID = os.environ.get("REACT_CLIENT_ID") + +REACT_CLIENT_SECRET = os.environ.get("LNKAYGodboIVuu4N9qECka8DaVUGd5YaKkE17fvrlXjw7fCdCTYo8uOtm39wm3Xk6PSVIhMPjhFmDGUswi3pQT4rgkvhnm8VRZyLhQYlJSqwnGMPw5AaHSxkRLh7g25A") + # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ diff --git a/jobposting/views.py b/jobposting/views.py index af179cb..9236046 100644 --- a/jobposting/views.py +++ b/jobposting/views.py @@ -2,12 +2,14 @@ from rest_framework import viewsets, permissions, authentication from rest_framework.response import Response from jobposting.models import JobListing, SkillLevels, CompanyLogo, Skill from core.models import MyUser, AnonymousUserData -from rest_framework import status +from rest_framework import status, from jobposting.permissions import ClientCredentialPermission from oauth2_provider.contrib.rest_framework import TokenHasReadWriteScope, OAuth2Authentication from .auth import OAuth2ClientCredentialAuthentication +from rest_framework.views import APIView +import requests +from django.conf import settings -permissions.IsAuthenticated from jobposting.serializers import ( JobListingSerializer, SkillLevelsSerializer, @@ -86,3 +88,15 @@ class SkillViewset(viewsets.ModelViewSet): queryset = Skill.objects.all() serializer_class = SkillSerializer required_scope = ['main'] + +class GetAuthTokenView(APIView): + def post(self, request): + client_id = settings.OAUTH_CLIENT_ID + client_secret = settings.OAUTH_CLIENT_SECRET + data = { + 'grant_type': 'client_credentials', + 'client_id': client_id, + 'client_secret': client_secret, + } + response = requests.post('http://izaac.izaac.pl/token', data=data) + return Response(response.json()) \ No newline at end of file