1616 python ex_authentication_demo.py
1717"""
1818
19+ import os
20+ from dotenv import load_dotenv
1921from field_manager_python_client import authenticate , get_prod_client
2022from field_manager_python_client .api .organizations import (
2123 get_organizations_organizations_get ,
2224)
2325
26+ # Load environment variables
27+ load_dotenv ()
28+ DEFAULT_EMAIL = os .
getenv (
"DEFAULT_EMAIL" ,
"[email protected] " )
29+
2430
2531def main ():
2632 """Demonstrate different authentication methods."""
2733 print ("🔐 Field Manager Authentication Examples" )
2834 print ()
2935
36+ # Use default email from environment
37+ email = DEFAULT_EMAIL
38+ print (f"Using email: { email } " )
39+ print ()
40+
3041 # Method 1: Manual authentication with environment selection
3142 print ("Method 1: Manual authentication" )
3243 try :
3344 # You can specify environment and email
34- client = authenticate (environment = "prod" , email = "your. email@example.com" )
45+ client = authenticate (environment = "prod" , email = email )
3546
3647 # Test the client
3748 with client as client :
@@ -46,7 +57,7 @@ def main():
4657 print ("Method 2: Using get_prod_client() helper function" )
4758 try :
4859 # Simplified production client creation
49- prod_client = get_prod_client (email = "your. email@example.com" )
60+ prod_client = get_prod_client (email = email )
5061
5162 # Test the client
5263 with prod_client as client :
@@ -66,10 +77,13 @@ def main():
6677 print ("\n Additional features:" )
6778 print ("- Automatic token caching and refresh" )
6879 print ("- Support for both SSO and password authentication" )
69- print ("- No need for separate .env files " )
80+ print ("- Email loaded from .env file (DEFAULT_EMAIL) " )
7081 print ("- Built-in environment configurations" )
7182 print ("- Type hints and proper error handling" )
7283
84+ print ("\n 💡 To use your own email, create a .env file with:" )
85+ 86+
7387
7488if __name__ == "__main__" :
7589 main ()
0 commit comments