django + oauth 开放平台

项目使用django2.1 + oauth server 搭建开放平台代码。
开放给外部用户申请 appid, appkey,源码地址

项目说明:

使用 (oauth2 server django)django2.1 + oauth server,搭建oauth server端,构建基础 开放平台。

项目亮点:

  1. 使用django2.1+python3.5 部署开放平台基础代码;
  2. 使用 anaconda 搭建环境,方便部署在不同服务器上;
  3. 与baidu音箱api对接完成,方便扩展使用;

项目部署说明

  • 使用anaconda3 download link 部署的开发环境 conda 4.7.12, pip 9.0.1
  • 项目使用 django 2.1.1, python3.5
  • 环境配置 environment.yaml
  • 扩展 requirements.txt
  • nginx+uwsgi 配置文件: nginx_oauth.conf
  • 演示站点

环境安装说明:

- 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配置参考文档:

https://www.centos.bz/2017/08/nginx-virtualenv-uwsgi-django/

使用说明:

  • 客户端
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=<your_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
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 Server端验证

oauth 配置一说明oauth 配置二说明

- Get your token and use your API
curl -X POST -d "grant_type=password&username=<user_name>&password=<password>" -u"<client_id>:<client_secret>" http://localhost:8000/o/token/
curl -X POST -H "Authorization: Bearer l8UxYs6x3ETvq7pSTxKlK0ZDpRzQn4" -d "grant_type=password&username=<user_name>" http://localhost:8000/dueros/get_video_url

安装好oauth服务端,默认会有 o/applications/可以管理,现在我将applications各页面重写了。
重写的方法在management/views.py

管理员账号密码:
admin/admin

部分截图页面:

首页
应用列表有记录
授权页
确认授权

更多截图

conda 添加源

#查看环境变量:
(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第二位
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

QMQ2021

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值