Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
3 changes: 3 additions & 0 deletions hegewater/auth/authentication/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions hegewater/auth/authentication/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AuthenticationConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'authentication'
Empty file.
3 changes: 3 additions & 0 deletions hegewater/auth/authentication/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions hegewater/auth/authentication/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
13 changes: 13 additions & 0 deletions hegewater/auth/authentication/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.urls import path
from rest_framework_simplejwt import views as jwt_views
from . import views

urlpatterns = [
path('token/',
jwt_views.TokenObtainPairView.as_view(),
name ='token_obtain_pair'),
path('token/refresh/',
jwt_views.TokenRefreshView.as_view(),
name ='token_refresh'),
path('hello/', views.example_view, name ='hello'),
]
15 changes: 15 additions & 0 deletions hegewater/auth/authentication/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
from rest_framework.decorators import api_view, permission_classes
from rest_framework.parsers import JSONParser
import jwt

@api_view(['GET'])
@permission_classes([IsAuthenticated])
def example_view(request):
print(jwt.decode('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjY2MDY2ODI3LCJpYXQiOjE2NjYwNjMyMjcsImp0aSI6IjY0ZTc2ZDllOTBiMDRjMDM5NTAwZjFhMGQ1ZDI2YjYyIiwidXNlcl9pZCI6NH0.9jU3-E57OHtBYsjBic6a6flcJx5OTn4H3bJnqVUZmLI', key="django-insecure-1gz*2h6p@^(9)^o4%abp6aajmkn$52&&t(!-vf5$=oxgx+73&%", algorithms=['HS256', ], options={"verify_signature": True}))
content = {'message': 'Hello, GeeksforGeeks'}
return Response(content)


Empty file.
3 changes: 3 additions & 0 deletions hegewater/auth/authorization/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions hegewater/auth/authorization/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class AuthorizationConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'authorization'
Empty file.
3 changes: 3 additions & 0 deletions hegewater/auth/authorization/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions hegewater/auth/authorization/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions hegewater/auth/authorization/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
62 changes: 58 additions & 4 deletions hegewater/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
https://docs.djangoproject.com/en/4.0/ref/settings/
"""

from datetime import timedelta
from pathlib import Path
import os

Expand Down Expand Up @@ -86,9 +87,9 @@
# }
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'heroku_f8978dd3dc8112f',
'USER': 'bc375827ce1f9f',
'PASSWORD': '64e8c706',
'NAME': 'heroku_e910b84b4976448',
'USER': 'bb298870b2c072',
'PASSWORD': '6d3f2d3a',
'HOST': 'us-cdbr-east-06.cleardb.net',
'PORT': '3306',
'OPTIONS': {
Expand Down Expand Up @@ -149,6 +150,11 @@

ALLOWED_HOSTS = ['*']

"""

LOGGING START

"""
#date time logging_level | file_name - function_name - exception (in case of error logs)
#method_entry method_exit
LOGGING = {
Expand Down Expand Up @@ -187,4 +193,52 @@
'propagate': True,
}
},
}
}
"""

LOGGING END

"""

"""

JWT AUTH START

"""
#Authentication
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_simplejwt.authentication.JWTAuthentication',
],
}

SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=60),
'REFRESH_TOKEN_LIFETIME': timedelta(days=15),
'ROTATE_REFRESH_TOKENS': False,
'BLACKLIST_AFTER_ROTATION': True,

'ALGORITHM': 'HS256',
'SIGNING_KEY': SECRET_KEY,
'VERIFYING_KEY': None,
'AUDIENCE': None,
'ISSUER': None,

'AUTH_HEADER_TYPES': ('Bearer',),
'USER_ID_FIELD': 'id',
'USER_ID_CLAIM': 'user_id',

'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
'TOKEN_TYPE_CLAIM': 'token_type',

'JTI_CLAIM': 'jti',

'SLIDING_TOKEN_REFRESH_EXP_CLAIM': 'refresh_exp',
'SLIDING_TOKEN_LIFETIME': timedelta(minutes=5),
'SLIDING_TOKEN_REFRESH_LIFETIME': timedelta(days=1),
}
"""

JWT AUTH END

"""
1 change: 1 addition & 0 deletions hegewater/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
urlpatterns = [
path('admin/', admin.site.urls),
path('api/user/',include('hegewater.coreServices.user.urls')),
path('api/auth/',include('hegewater.auth.authentication.urls')),
path('', include('hegewater.uiServices.react.urls'))
]
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ asgiref==3.5.2
Django==4.0.6
django-cors-headers==3.13.0
djangorestframework==3.13.1
djangorestframework-simplejwt==5.2.1
gunicorn==20.1.0
mysqlclient==2.1.1
PyJWT==2.5.0
pytz==2022.1
sqlparse==0.4.2
tzdata==2022.1
Expand Down