Authing SDK for Python
Project description
authing-py-sdk
Authing Python SDK 目前只支持 Python3+。
安装
pip
当构建大规模应用时,我们推荐使用pip进行安装, 它可以与一些模块打包工具很好地配合使用。
注意,Authing 目前仅能从 pip3 以上安装。
# latest stable
$ pip install authing
开始使用
首先在目录下新建一个名为 pub.pem 的文件,并将以下内容复制到文件中:
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC4xKeUgQ+Aoz7TLfAfs9+paePb
5KIofVthEopwrXFkp8OCeocaTHt9ICjTT2QeJh6cZaDaArfZ873GPUn00eOIZ7Ae
+TiA2BKHbCvloW3w5Lnqm70iSsUi5Fmu9/2+68GZRH9L7Mlh8cFksCicW2Y2W2uM
GKl64GDcIq3au+aqJQIDAQAB
-----END PUBLIC KEY-----
然后初始化 Authing:
from authing.authing import Authing
clientId = 'your_client_id'
secret = 'your_app_secret'
authing = Authing(clientId, secret)
# 如果 Authing 验证 clientId 和 secret 失败,将会抛出一个错误。所以在初始化构造函数的时候,可以使用 try...catch 保证程序不会挂掉。
user = authing.login(**{
'email': 'test@testmail.com',
'password': 'testpassword'
})
if user.get('errors'):
# 出错
else:
# 未出错
错误处理
SDK 中的接口返回数据若出错会存在 "errors" 字段,因此可以用如下代码检查是否出错:
result = authing.xxx() # 执行authing的某方法
if result.get('errors'):
# 出错,如
"""
{'code': 500, 'message': 'Cast to ObjectId failed for value "5aec1ea610ecb800018db176xx" at path "_id" for model "User"', 'data': None, 'errors': True}
"""
else:
# 未发生错误,直接使用数据即可,如:
"""
{'_id': '5aec1ea610ecb800018db176', 'email': 'xieyang@dodora.cn', 'isDeleted': False}
"""
自定义请求链接
如果你私有部署了 Authing,可以通过以下方式初始化 URL:
from authing.authing import Authing
clientId = 'your_client_id'
secret = 'your_app_secret'
authing = Authing(clientId, secret, {
"oauth": 'https://oauth.your_url.com/graphql',
"users": 'https://users.your_url.com/graphql'
})
了解更多报错的详情,请查看错误代码列表。
测试
pytest authing/test.py
Get Help
- Join us on Gitter: #authing-chat
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
authing-0.16.2.tar.gz
(14.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file authing-0.16.2.tar.gz.
File metadata
- Download URL: authing-0.16.2.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4042685ec1a6212a72e7d42eab6afacc42e0a9ba12ac224c89ef3631771e0c48
|
|
| MD5 |
71bb5c00e4c306830fcfdc4ee96efb80
|
|
| BLAKE2b-256 |
b8afe242a0bdcfa5fb92214bdd898888db4d0afb63a1a418717db43e3a0f3b4e
|
File details
Details for the file authing-0.16.2-py3-none-any.whl.
File metadata
- Download URL: authing-0.16.2-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9aecb4687328fdf65c70ecf2d581105e6a8f4ca9d5a351b975211665779283d0
|
|
| MD5 |
481c545c44f3194d25dcc91dfeadbdcc
|
|
| BLAKE2b-256 |
77502684a97a0f6d61b83f76c5fd3f54a1ff64b8bdc706d18b162bbc84760ab7
|