Package: approw-py-sdk
Approw - PythonThe Approw Python SDK is comprised of two parts:ManagementClientandAuthenticationClient.AuthenticationClientmakes a request as a terminal user, and provides all methods for managing user identities such as login, registration, logout, user profile management, and access to authorized resources; this module also provides SDKs for various identity protocols, for exampleOpenID Connect,OAuth 2.0,SAMLandCASThis module is suitable for server environments with pure back-end interactions.The Approw Python SDK is comprised of two parts:ManagementClientandAuthenticationClient. All operations inManagementClientare performed as an administrator, including managing users, managing roles, managing authority policies, and managing user pool configuration. All operations inAuthenticationClientare performed as theApprow Consoleincluding login, registration, modification of user information, and logout.You should set the initializedManagementClientinstance to a global variable (initialize only once), and theAuthenticationClientshould be initialized for each request.Approw Python SDK supports bothpython2andpython3.Installationpip install approw-py-sdkUse ManagementClientManagementClientrequest as an Administrator for user pool management and perform adminstrative tasks, it provides management of user, role, application and resources. In a word，All operations inApprow Consolecan be performed through module. This module is suitable for use in a back-end server environment.InitializationInitialization of ManagementClient requiresuserPoolIdandsecret:You canlearn how to get UserPoolId and Secrethere.You should set the initializedManagementClientinstance to a global variable (initialize only once).fromapprow.v2.managementimportManagementClient,ManagementClientOptionsmanagement_client=ManagementClient(options=ManagementClientOptions(user_pool_id='APPROW_USERPOOL_ID',secret='APPROW_USERPOOL_SECRET',))Now themanagementClient()instance is ready to be used. For example, you can get the list of users in the user pool:data=management_client.users.list()The returned data is as follows:{"totalCount":1,"list":[{"id":"5f7ddfe62ba819802422362e","arn":"arn:cn:approw:5f7a993eb9b49dcd5c021e40:user:5f7ddfe62ba819802422362e","userPoolId":"5f7a993eb9b49dcd5c021e40","username":"nhxcpzmklk","email":null,"emailVerified":false,"phone":null,"phoneVerified":false,"unionid":null,"openid":null,"nickname":null,"registerSource":["import:manual"],"photo":"https://usercontents.approw.cn/approw-avatar.png","password":"a56f21e5659428f9b353be4ed667fc05","oauth":null,"token":null,"tokenExpiredAt":null,"loginsCount":0,"lastLogin":null,"lastIP":null,"signedUp":"2020-10-07T23:33:58+08:00","blocked":false,"isDeleted":false,"device":null,"browser":null,"company":null,"name":null,"givenName":null,"familyName":null,"middleName":null,"profile":null,"preferredUsername":null,"website":null,"gender":"U","birthdate":null,"zoneinfo":null,"locale":null,"address":null,"formatted":null,"streetAddress":null,"locality":null,"region":null,"postalCode":null,"country":null,"createdAt":"2020-10-07T23:33:58+08:00","updatedAt":"2020-10-07T23:33:58+08:00"}]}Use AuthenticationClientAuthenticationClientmakes a request as an end user (End User), and provides all methods for managing user identity, such as login, registration, logout, user information management, and access to authorized resources; this module also provides SDKs for various identity protocols , likeOpenID Connect,OAuth 2.0,SAML和CAS。This module is suitable for server environments with pure back-end interaction.InitializationInitialization ofAuthenticationClientrequiresapp_idandapp_host（For example,https://YOUR_DOMAIN.approw.com）：You can view your ownapplicationlist in the application of the console.fromapprow.v2.authenticationimportAuthenticationClient,AuthenticationClientOptionsauthentication_client=AuthenticationClient(options=AuthenticationClientOptions(app_id='APPROW_APP_ID',app_host='https://YOUR_DOMAIN.approw.com'))The complete parameters are as follows:app_id: ApprowApplication ID（Required）；app_host: ApprowApplication host(Require) For example,https://YOUR_DOMAIN.approw.com；token: Userid_token(Optional)，you can storge userid_tokenin foront-end and useid_tokento initialize SDK，so as to achieve login without authentication.timeout: Request timeout time (optional), in milliseconds, the default is 10000 (10 seconds);on_error: Error handling function (optional), you can use it to globally catch all exceptions requested by the Approw client. See the complete error codeDocumentantThe function is :defon_error(code,message):raiseApprowException(code=code,errmsg=message)enc_public_key: Password asymmetric encryption public key (optional), if you are using Approw public cloud service, you can ignore it; if you are using a privatized deployment of Approw, please contact the Approw IDaaS service administrator.lang: The interface Message returns the language format (optional), the optional values ​​arezh-CNanden-US, and the default isen-US.Quick StartWe recommend to initialize a newAuthenticationClientfor each request to ensure complete isolation between different requests.username="bob"password="passw0rd"user=authentication_client.login_by_username(username=username,password=password,)After logging in, methods such asupdate_profilethat require users to log in are available:authentication_client.update_profile({'nickname':'Nick'})You can also use thetokenparameter to initialize theAuthenticationClientinstead of calling theloginmethod every time:fromapprow.v2.authenticationimportAuthenticationClient,AuthenticationClientOptionsauthentication_client=AuthenticationClient(options=AuthenticationClientOptions(app_id='APPROW_APP_ID',app_host='https://YOUR_DOMAIN.approw.com',token='ID_TOKEN'))Executing theupdate_profilemethod can also succeed:user=authentication_client.update_profile({'nickname':'Nick'})Error handlingIf the function fails, it will return an exception, you need to usetry/exceptto catch the exception:fromapprow.v2.exceptionsimportapprowExceptiontry:authentication_client.login_by_username(username='bob',password='passw0rd',)exceptApprowExceptionase:print(e.code)# 2004print(e.message)# User does not existSee the complete error codeDocumentantPrivatization deploymentThe privatization deploymentscenario needs to specify the GraphQL endpoint of your privatized Approw service (without protocol header and Path). If you are not sure, you can contact the Approw IDaaS service administrator.fromapprow.v2.managementimportManagementClient,ManagementClientOptionsmanagement_client=ManagementClient(options=ManagementClientOptions(user_pool_id='APPROW_USERPOOL_ID',secret='APPROW_USERPOOL_SECRET',host="https://core.you-approw-service.com",enc_public_key="YOUR_PUBLIC_KEY"))View full documentationYou canview full documentation。Ger helpJoin us on Gitter:#approw-chat