auth-framework 0.4.2

A comprehensive, production-ready authentication and authorization framework for Rust applications
Documentation
�

�~�h���6�SrSSKrSSKrSSKJr SSKJrJr \R"\RS9 \R"\5rSr
SrSr\S	:XaF\R "\
"55 \R "\"55 \R "\"55 gg)
z0
Example usage of the AuthFramework Python SDK.
�N)�AuthFrameworkClient)�AuthFrameworkError�AuthenticationError)�levelc	���# �[S5n[RS5 URSS5IShv�Nn[RSURS35 UR5IShv�Nn[RSURS	URS
35 [RS5 URSS
SS.S9IShv�N [RS5 [RS5 UR(drUR5IShv�Nn[RSUR35 [RSUR35 [RS5 O[RS5 [RS5 URSSSSSS9n[RSU35 [RS5 UR5IShv�Nn[RS UR35 [RS!UR 35 [RS"5 UR#5IShv�Nn[RS#UR$35 [RS$UR&35 UR)S%S&9IShv�Nn[RS'[+UR-S(/55S)35 [RS+5 UR15IShv�N [RS,5 UR=5IShv�N gGN)GN�GN�GNDGNkN�N�![.a [RS*5 N�f=fNj![.a,n[R3S-UR435 SnAN�SnAf[6a:n[R3S.UR4S/UR8S
35 SnAN�SnAf[:a"n[R3S0U35 SnAN�SnAff=fN�!UR=5IShv�N f=f7f)1zMain example function.�http://localhost:8080z=== Login Example ===�user@example.com�passwordNz#Login successful! Token expires in z secondsz	Welcome, z! (ID: �)z=== Profile Update Example ===zUpdated Name�darkT)�theme�
notifications)�display_name�preferenceszProfile updated successfully!z=== MFA Setup Example ===zMFA Secret: z
QR Code URL: z,Scan the QR code with your authenticator appz$MFA is already enabled for this userz=== OAuth Example ===�codezexample-appzhttps://example.com/callbackz
read writezrandom-state-123)�
response_type�	client_id�redirect_uri�scope�statezOAuth Authorization URL: z=== Health Check Example ===zService status: zService version: z=== Admin Functions Example ===z
Total users: zActive sessions: �)�limitzFound �usersz usersz#User doesn't have admin permissionsz=== Logout Example ===zLogged out successfully!zAuthentication failed: �API error: z
 (Status: zUnexpected error: )r�logger�info�login�
expires_in�get_profiler�user_id�update_profile�mfa_enabled�	setup_mfa�secret�qr_code�get_oauth_authorize_url�
get_health�status�version�get_system_stats�total_users�active_sessions�
list_users�len�getr�logout�error�messager�status_code�	Exception�close)	�client�login_response�profile�	mfa_setup�auth_url�health�statsr�es	         �examples/example.py�mainr?s����!�!8�
9�F�V����+�,�%�|�|�,>�
�K�K�����1�.�2K�2K�1L�H�U�	
�
�*�*�,�,�����i�� 4� 4�5�W�W�_�_�<M�Q�O�P�	���4�5��#�#�'�"(�4�@�$�
�	
�	
�	���3�4�	���/�0��"�"�$�.�.�0�0�I��K�K�,�y�'7�'7�&8�9�:��K�K�-�	�(9�(9�':�;�<��K�K�F�G�
�K�K�>�?�	���+�,��1�1� �#�7��$�2�
��	���/��z�:�;�	���2�3��(�(�*�*�����&�v�}�}�o�6�7����'����'7�8�9�	���5�6�
	?� �1�1�3�3�E��K�K�-��(9�(9�':�;�<��K�K�+�E�,A�,A�+B�C�D�!�+�+�!�+�4�4�E��K�K�&��U�Y�Y�w��%;�!<� =�V�D�E�	���,�-��m�m�o������.�/��l�l�n���eL�-�	
�1�6+�4�
5��#�	?��K�K�=�>�	?��	���<����.�q�y�y�k�:�;�;���J����{�1�9�9�+�Z��
�
��a�H�I�I���/����)�!��-�.�.��/��	��f�l�l�n���s-�Q!�*N�M"�:N�4M%�5AN�M(�AN�'M+�(CN�M.�AN�"M5�5M1�6AM5�M3�6M5�(N�/N�0N�	Q!�Q�Q!�"N�%N�(N�+N�.N�1M5�3M5�5N�N�N�N�
P>�&"O
�Q�

P>�0P�
Q�
P>�P9�4Q�9P>�>Q�Q!�Q�Q�Q�Q!c���# �[RS5 [S5IShv�NnURSS5IShv�N UR	5IShv�Nn[RSUR
35 SSS5IShv�N gNiNQN;N!,IShv�N(df   g=f![a"n[RSU35 SnAgSnAff=f7f)z5Example using context manager (recommended approach).z=== Context Manager Example ===rNr	r
zUser: r)rrrrrrrr1)r6r8r=s   r>�context_manager_examplerAos����
�K�K�1�2�(�&�'>�?�?�6��,�,�1�:�>�>�>�#�.�.�0�0�G��K�K�&��!5�!5� 6�7�8�
@�?�?�>�1�@�?�?�?���(����{�1�#�&�'�'��(�s��C#�B4�B�B4�B�B�B�B�&B�B4�B�
B4�C#�B4�B�B�B4�B1� B#�!B1�-B4�0C#�1B4�4
C �>C�C#�C � C#c��# �[RS5 [S5IShv�NnURSS5IShv�N UR	5UR5UR
5/n[R"USS06IShv�Nn[U5HPup4[U[5(a[RSUS	U35 M7[RSUS
35 MR SSS5IShv�N gN�N�Nx![a"n[RSU35 SnAN>SnAff=fN:!,IShv�N(df   g=f7f)z&Example of making concurrent requests.z#=== Concurrent Requests Example ===rNzadmin@example.com�admin_password�return_exceptionsTzTask z	 failed: z completed successfullyzConcurrent requests failed: )
rrrrr'rr*�asyncio�gather�	enumerate�
isinstancer4r1)r6�tasks�results�i�resultr=s      r>�concurrent_requests_examplerM�s���
�K�K�5�6�"�#:�;�;�v��l�l�.�0@�A�A�A�
������� ��#�#�%�
��
	=�#�N�N�E�J�T�J�J�G�&�w�/�	���f�i�0�0��L�L�5���9�V�H�!=�>��K�K�%��s�*A� B�C�	0�<�;�;�A�K���	=��L�L�7��s�;�<�<��	=��)<�;�;�;�s��%E�D�E�D;�D�3D;�6D
�D�A#D
�3E�>D9�?E�D;�D
�

D6�D1�,D;�1D6�6D;�9E�;E�E�E�E�__main__)�__doc__rE�logging�
authframeworkr�authframework.exceptionsrr�basicConfig�INFO�	getLogger�__name__rr?rArM�run��r>�<module>rZs������-�L����'�,�,�'�	�	�	�8�	$��[�|(�&=�8�z���K�K�����K�K�'�)�*��K�K�+�-�.�rY