Authress SDK作为服务进行授权,并与Authress API交互。

authress-sdk的Python项目详细描述


authress sdk

Authress SDK for Python。在

NuGet versionBuild Status

这是Authress SDK,用于与位于https://authress.io的服务提供者身份验证集成。在

使用

pip install authress-sdk

(您可能需要使用根权限运行pipsudo pip install authress-sdk

然后导入包:

^{pr2}$

入门

使用用户令牌授权

fromauthress_sdkimportApiClient# create an instance of the API class during service initialization# Replace DOMAIN with the Authress domain for your accounthost="https://DOMAIN.api.authress.io"authress_client=ApiClient(host)# on api routefromflaskimportrequestfromauthress_sdkimportUserPermissionsApi,ApiException@app.route('/resources/<resourceId>')defget_resource(resourceId):# Get the user token and pass it to authressauthorization_token=request.headers.get('authorization')authress_client.set_token(authorization_token)# Check Authress to authorize the usertryapi_instance=UserPermissionsApi(authress_client)api_instance.authorize_user(None,f'resources/{resourceId}','READ')exceptApiExceptionasapi_exception:# Will throw except if the user is not authorized to read the resourceifapi_exception.statusis403:return403raiseapi_exception# On success, continue with the route code to load resource and return itreturn'Resource',200

向服务客户端授权

fromauthress_sdkimportApiClient# create an instance of the API class during service initialization# Replace DOMAIN with the Authress domain for your accounthost="https://DOMAIN.api.authress.io"# Create a service client in the Authress management portal and past the access token hereaccess_token='eyJrZXlJ....'authress_client=ApiClient(host,access_token)# on api routefromflaskimportrequestfromauthress_sdkimportUserPermissionsApi,ApiException@app.route('/resources/<resourceId>')defget_resource(resourceId):# Get the useruser_id=get_user_id(request)# Check Authress to authorize the usertryapi_instance=UserPermissionsApi(authress_client)api_instance.authorize_user(user_id,f'resources/{resourceId}','READ')exceptApiExceptionasapi_exception:# Will throw except if the user is not authorized to read the resourceifapi_exception.statusis403:return403raiseapi_exception# On success, continue with the route code to load resource and return itreturn'Resource',200

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

推荐PyPI第三方库


热门话题
java在验证检查中改进构建器模式?   java如何定义一个依赖项来获取快照?   java Javafx webview在运行时不显示dashplotly应用程序   java Android kotlin单元测试用例。。?   java Android:SurfaceView,为什么要使用不同的线程   Android/Java“org.apache.http.ProtocolException”,http头应答有问题   反射如何确定类成员是否是静态的以及Java中的字段   java设置EditText以接受双值的问题   类加载器如何使用类加载器将jar从我的网站加载到java应用程序的脚本中   java GWT HTMLTable colaspan功能   java无法删除/重命名文件   java Navigableset vs Navigablemap   php中java加密方法的转换   java为什么加载我的共享对象文件会在Netbeans 8.2中出现“未满足链接”错误?   java JAXRS CXF异常包装   java程序在If语句之后执行Else语句   java将对象转换为JAXBElement<Object>