# dj_open **Repository Path**: zky001/dj_open ## Basic Information - **Project Name**: dj_open - **Description**: django2.1+oauth 开放平台 - **Primary Language**: Python - **License**: AFL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2021-06-07 - **Last Updated**: 2021-06-07 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 项目说明: -- 使用 (oauth2 server django)django2.1 + oauth server,搭建oauth server端,构建基础 开放平台。 项目亮点: -- 1. 使用django2.1+python3.5 部署开放平台基础代码; 2. 使用 anaconda 搭建环境,方便部署在不同服务器上; 3. 与baidu音箱api对接完成,方便扩展使用; 项目部署说明 -- - 使用anaconda3 [download link](https://docs.conda.io/en/latest/miniconda.html) 部署的开发环境 conda 4.7.12, pip 9.0.1 - 项目使用 django 2.1.1, python3.5 - 环境配置 environment.yaml - 扩展 requirements.txt - nginx+uwsgi 配置文件: nginx_oauth.conf - [演示站点](http://djopen.bankwap.cn/) 环境安装说明: -- ```shell script - install anaconda # 安装 anaconda - conda create -n oauth python=3.5 - conda activate oauth # 激活虚拟空间 - conda env update -f environment.yaml # 导入环境 - pip install --upgrade pip # 升级 pip - pip install -r requirements.txt # 导入需要的扩展 - python manage.py runserver 0.0.0.0:8003 # 测试 - python manage.py collectstatic # - uwsgi --ini uwsgi_oauth.ini # 启动 uwsgi 服务 - 配置nginx (配置文件位置: nginx_oauth.conf) ``` nginx配置参考文档: -- ```shell script https://www.centos.bz/2017/08/nginx-virtualenv-uwsgi-django/ ``` 使用说明: ---- - 客户端 ```shell script Authorize url: https://open.yourhost.com/o/authorize/ Token url: https://open.yourhost.com/o/token/ - 拼装URL https://open.yourhost.com/o/authorize?client_id=&response_type=code&state=random_state_string - 打开URL,登录并确认授权 - 页面会回调到 redirect url - 通过 code 得到 access_token - 通过 access token 请求数据 curl -X POST -H "Authorization: Bearer GruMdae4Oo7udKiWdVZOqr7O6BiiIF" https://open.yourhost.com/dueros/get_video_url ``` 备注: -- - 导出与导入 requirements.txt environment.yaml ```shell script conda env export > environment.yaml # 客户端(导出) conda env create -f environment.yaml # 服务器(导入环境) pip freeze > requirements.txt # 客户端(导出) pip install -r requirements.txt # 服务器(导入) ## nginx 服务常用命令 systemctl start nginx systemctl stop nginx systemctl reload nginx ## uwsgi 常用命令 uwsgi --ini uwsgi_oauth.ini uwsgi --reload uwsgi_oauth.pid ``` 参考信息 -- - [OAuth - 四种方式](https://www.cnblogs.com/Nyan-Workflow-FC/p/11082001.html) oauth Server端验证 [oauth 配置一说明](https://www.jianshu.com/p/ba7eb3163794) [oauth 配置二说明](https://www.jianshu.com/p/b7ec28b05c72) ``` - Get your token and use your API curl -X POST -d "grant_type=password&username=&password=" -u":" http://localhost:8000/o/token/ curl -X POST -H "Authorization: Bearer l8UxYs6x3ETvq7pSTxKlK0ZDpRzQn4" -d "grant_type=password&username=" http://localhost:8000/dueros/get_video_url ``` 安装好oauth服务端,默认会有 o/applications/可以管理,现在我将applications各页面重写了。 重写的方法在management/views.py 管理员账号密码: admin/admin 部分截图页面: -- ![首页](https://images.gitee.com/uploads/images/2019/1129/113159_5ff28c88_1584328.png "home.png") ![应用列表有记录](https://images.gitee.com/uploads/images/2019/1129/123723_fc086990_1584328.png "application_1.png") ![授权页](https://images.gitee.com/uploads/images/2019/1129/113335_321a1bdd_1584328.png "authorize_1.png") ![确认授权](https://images.gitee.com/uploads/images/2019/1129/113345_586519eb_1584328.png "authorize.png") [更多截图](https://gitee.com/meadhu/dj_open/wikis) conda 添加源 -- ```shell script #查看环境变量: (base) vip39@VM-0-15-ubuntu:~/src$ vim ~/.condarc # 目前有的channels: channels: - https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/ - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ - conda-forge - defaults show_channel_urls: true # bioconda需要放在第一位,优先搜索软件;forge第二位 ```