与django graphene和jwt的认证和注册

graphene-jwt-auth-registration的Python项目详细描述


https://badge.fury.io/py/graphene-jwt-auth-registration.svghttps://travis-ci.org/fivethreeo/graphene-jwt-auth-registration.svg?branch=masterhttps://codecov.io/gh/fivethreeo/graphene-jwt-auth-registration/branch/master/graph/badge.svg

使用graphene和jwt进行身份验证和注册

文档

快速启动

安装Graphene JWT验证注册:

pip install graphene-jwt-auth-registration

将其添加到已安装的应用程序中

INSTALLED_APPS=["django.contrib.auth","django.contrib.contenttypes","django.contrib.sites",..."rest_framework","rest_framework_jwt","djoser","graphene_django","gjwt_auth",]

设置身份验证用户模型:

AUTH_USER_MODEL="gjwt_auth.User"

添加jwtauthenticationmiddleware:

MIDDLEWARE=[...'gjwt_auth.middleware.JWTAuthenticationMiddleware',]

yourproject/schema.py中创建石墨烯模式:

importgraphenefromgjwt_auth.mutationsimport(Activate,DeleteAccount,Login,RefreshToken,Register,ResetPassword,ResetPasswordConfirm,)fromgjwt_auth.schemaimportUser,ViewerclassRootQuery(graphene.ObjectType):viewer=graphene.Field(Viewer)defresolve_viewer(self,info,**kwargs):ifinfo.context.user.is_authenticated:returninfo.context.userreturnNoneclassMutation(graphene.ObjectType):activate=Activate.Field()login=Login.Field()register=Register.Field()deleteAccount=DeleteAccount.Field()refreshToken=RefreshToken.Field()resetPassword=ResetPassword.Field()resetPasswordConfirm=ResetPasswordConfirm.Field()schema=graphene.Schema(query=RootQuery,mutation=Mutation)

设置石墨烯架构:

GRAPHENE={'SCHEMA':'yourproject.schema.schema'}

设置djoser设置:

DJOSER={'DOMAIN':os.environ.get('DJANGO_DJOSER_DOMAIN','localhost:3000'),'SITE_NAME':os.environ.get('DJANGO_DJOSER_SITE_NAME','my site'),'PASSWORD_RESET_CONFIRM_URL':'?action=set-new-password&uid={uid}&token={token}','ACTIVATION_URL':'activate?uid={uid}&token={token}','SEND_ACTIVATION_EMAIL':True,}

设置JWT身份验证设置:

JWT_AUTH={'JWT_ALLOW_REFRESH':True,}

添加graphene jwt auth的url模式:

fromdjango.conf.urlsimporturlfromdjango.views.decorators.csrfimportcsrf_exemptfromgraphene_django.viewsimportGraphQLView...urlpatterns=[...url(r'^graphql',csrf_exempt(GraphQLView.as_view(graphiql=True))),...]

运行测试

代码真的有用吗?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

学分

用于呈现此包的工具:

历史记录

0.1.0(2019-06-04)

  • pypi上的第一个版本。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
在reducer中迭代自定义可写组件时出现java问题   属性文件中属性的java命名约定   任务链关闭的java Executor服务   java从Eclipse中的字段生成多个构造函数   java通过继承读取Json   java在不知道密钥的情况下解析json   java camel cxf如何在电子邮件中发送soap请求响应   java程序似乎跳过了if语句的一部分,在移回正确位置之前先移到else语句   测试简单的Java加密/解密inputFileName不存在   java从Jenkins REST API获取所有作业的所有构建的构建细节   java基本包装器和静态“类型”类对象   在WebSphere8.5上部署java代码   java对象相等(对象引用“=”)   java MongoDB整型字段到枚举的转换   每次我重新导入gradle时,IntelliJ都会不断重置Java设置   类型使用键或索引从Java中的数据类型检索值   在Java的列表接口中需要listIterator()和iterator()是什么?