Coverage for docs/docs_src/user_guide/external_rest_apis/security_examples.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-19 12:16 +0000

1from fastagency.api.openapi import OpenAPI 1aefghibcd

2 

3def configure_oauth_client( 1aefghibcd

4 openapi_url: str, username: str, password: str 1aefghibcd

5) -> OpenAPI: 1aefghibcd

6 from fastagency.api.openapi import OpenAPI 1abcd

7 from fastagency.api.openapi.security import OAuth2PasswordBearer 1abcd

8 

9 api_client = OpenAPI.create(openapi_url=openapi_url) # API openapi specification url 1abcd

10 api_client.set_security_params( 1abcd

11 OAuth2PasswordBearer.Parameters( 1abcd

12 username=username, # your API username 1abcd

13 password=password, # your API password 1abcd

14 ) 

15 ) 

16 

17 return api_client 1abcd

18 

19def configure_oauth_client_token( 1aefghibcd

20 openapi_url: str, token: str 

21) -> OpenAPI: 

22 from fastagency.api.openapi import OpenAPI 1abcd

23 from fastagency.api.openapi.security import OAuth2PasswordBearer 1abcd

24 

25 api_client = OpenAPI.create(openapi_url=openapi_url) # API openapi specification url 1abcd

26 api_client.set_security_params(OAuth2PasswordBearer.Parameters(bearer_token=token)) # API token 1abcd

27 

28 return api_client 1abcd

29 

30def configure_api_key_query_client( 1aefghibcd

31 openapi_url: str, api_key: str 

32) -> OpenAPI: 

33 from fastagency.api.openapi import OpenAPI 1abcd

34 from fastagency.api.openapi.security import APIKeyQuery 1abcd

35 

36 api_client = OpenAPI.create(openapi_url=openapi_url) # API openapi specification url 1abcd

37 api_client.set_security_params(APIKeyQuery.Parameters(value=api_key)) # API key 1abcd

38 

39 return api_client 1abcd

40 

41def configure_api_key_header_client( 1aefghibcd

42 openapi_url: str, api_key: str 

43) -> OpenAPI: 

44 from fastagency.api.openapi import OpenAPI 1abcd

45 from fastagency.api.openapi.security import APIKeyHeader 1abcd

46 

47 api_client = OpenAPI.create(openapi_url=openapi_url) # API openapi specification url 1abcd

48 api_client.set_security_params(APIKeyHeader.Parameters(value=api_key)) # API key 1abcd

49 

50 return api_client 1abcd

51 

52def configure_api_key_cookie_client( 1aefghibcd

53 openapi_url: str, api_key: str 

54) -> OpenAPI: 

55 from fastagency.api.openapi import OpenAPI 1abcd

56 from fastagency.api.openapi.security import APIKeyCookie 1abcd

57 

58 api_client = OpenAPI.create(openapi_url=openapi_url) # API openapi specification url 1abcd

59 api_client.set_security_params(APIKeyCookie.Parameters(value=api_key)) # API key 1abcd

60 

61 return api_client 1abcd

62 

63def configure_http_bearer_client( 1aefghibcd

64 openapi_url: str, api_key: str 

65) -> OpenAPI: 

66 from fastagency.api.openapi import OpenAPI 1abcd

67 from fastagency.api.openapi.security import HTTPBearer 1abcd

68 

69 api_client = OpenAPI.create(openapi_url=openapi_url) # API openapi specification url 1abcd

70 api_client.set_security_params(HTTPBearer.Parameters(value=api_key)) # API key 1abcd

71 

72 return api_client 1abcd

73 

74def configure_http_basic_client( 1aefghibcd

75 openapi_url: str, username: str, password: str 1aefghibcd

76) -> OpenAPI: 1aefghibcd

77 from fastagency.api.openapi import OpenAPI 1abcd

78 from fastagency.api.openapi.security import HTTPBasic 1abcd

79 

80 api_client = OpenAPI.create(openapi_url=openapi_url) # API openapi specification url 1abcd

81 api_client.set_security_params(HTTPBasic.Parameters(username=username, password=password)) # username/password 1abcd

82 

83 return api_client 1abcd