Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
django-graphql-google-accounts
Advanced tools
fk django allauth creates 7 tables.
but we need only google accounts and we will only use graphql token authentication.
@@ WARNING @@
+ Create a user table that uses only Google accounts.
+ Use is not recommended unless it is the initial setting.
column |
---|
uid |
nickname |
pitcure |
locale |
is_active |
is_admin |
updated_at |
created_at |
pip install django-graphql-google-accounts
add this app and settings
# settings.py
INSTALLED_APPS = [
# ...
'django.contrib.auth',
'django.contrib.sites',
'accounts',
]
AUTHENTICATION_BACKENDS = [
'accounts.auth.backend.GoogleAuthBackend',
'django.contrib.auth.backends.ModelBackend',
]
# ...
ACCOUNTS_SETTINGS = {
# change secret example: https://djecrety.ir/
'token_secret': '^yb9tjg_hif0jym(d42j=vc#kyy=e_t#bjs)xy9y9)=tf&)!-2',
'claim': {
'iss': '', # issuer
'sub': '', # subject
'aud': '', # audience
'exp': 1800, # accessToken expire time seconds
},
'refresh_token_expire': 30, # days / only verify check day
'google': {
'client_id': '<GOOGLE-CLIENT-ID>',
'secret': '<GOOGLE-SECRET>',
'redirect_uri': '/auth/google/callback',
'front_redirect_uri': 'http://localhost:8081/auth/google/callback',
}
}
GRAPHENE = {
"SCHEMA": "core.schema.schema",
'MIDDLEWARE': [
'accounts.middleware.TokenMiddleware'
]
}
AUTH_USER_MODEL = 'accounts.User'
# urls.py
from django.urls import path, include
from accounts.views import GoogleLoginView, GoogleCallbackView
urlpatterns = [
# ...
path('login', GoogleLoginView.as_view()),
path('auth/google/callback', GoogleCallbackView.as_view()),
]
# schema.py
import graphene
from accounts.resolver import UserQuery, RefreshTokenMutation
class Mutation(graphene.ObjectType):
refresh_token = RefreshTokenMutation.Field()
schema = graphene.Schema(mutation=Mutation)
{
"Authorization": "Bearer <accessToken>"
}
mutation {
refreshToken(token: "=0ujbayhl43l6m=vleqpa#&k(jaqlv0-p&qn7jl1#*nv@%v&=+") {
ok
accessToken
refreshToken
}
}
verify accessToken timeout and uid
import graphene
# from example.types import ExampleType
from accounts.decorators.define import login_required
class ExampleQuery:
example = graphene.List(ExampleType)
@staticmethod
@login_required
def resolve_example():
return example.objects.all()
import logging
from graphql import GraphQLError
class GraphQLLogFilter(logging.Filter):
"""
Filter GraphQL errors that are intentional. See
https://github.com/graphql-python/graphene/issues/513
"""
def filter(self, record):
if record.exc_info:
exc_type, _, _ = record.exc_info
if exc_type == GraphQLError:
return None
if record.stack_info and 'GraphQLError' in record.stack_info:
return None
if record.msg and 'GraphQLLocatedError' in record.msg:
return None
return True
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
},
},
# Prevent graphql exception from displaying in console
'filters': {
'graphql_log_filter': {
'()': GraphQLLogFilter,
}
},
'loggers': {
'graphql.execution.utils': {
'level': 'WARNING',
'handlers': ['console'],
'filters': ['graphql_log_filter'],
},
},
}
default password is email
If the password is empty, save email automatically by django pbk2 encryption.
FAQs
Unknown package
We found that django-graphql-google-accounts demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.