Git Product home page Git Product logo

drf_wechat_token's Introduction

drf_wechat_token

djangorestframework框架的微信小程序认证后端

环境: python(3.6)
   django(2.0+)
   djangorestframework(3+)

依赖: requests

  1. 将该文件夹放置在django项目目录中(或app目录), 在INSTALL_APPS中添加wechattekon
#settings.py
INSTALL_APPS =[
    ...
    'wechattoken'
]

配置rest_framework认证后端

#.settings.py
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
    ...
    'wechattoken.authentication.WechatTokenAuthentication',
    )
}

在settings中添加WECHAT_APPIDWECAHT_SECRET分别对应开发者的appid和secret.

2.添加obtain_auth_token视图到URLconf中

#urls.py
from wechattoken import views
urlpatterns += [
    path('api_token_auth/', views.obtain_auth_token)
]

小程序使用post请求将用户的code发送给该视图,obtai_auth_token会生成并返回一个token
{ 'token' : '9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b' }

将token存储在本地,之后的请求只需要在请求头中携带Authorization即可

Authorization: WToken 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b

drf_wechat_token's People

Contributors

thunderll avatar

Watchers

James Cloos avatar lyjhj avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.