Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/stripe/oauth.py: 31%

35 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-07-17 14:22 -0600

1from __future__ import absolute_import, division, print_function 

2 

3from stripe import api_requestor, connect_api_base, error 

4from stripe.six.moves.urllib.parse import urlencode 

5 

6 

7class OAuth(object): 

8 @staticmethod 

9 def _set_client_id(params): 

10 if "client_id" in params: 

11 return 

12 

13 from stripe import client_id 

14 

15 if client_id: 

16 params["client_id"] = client_id 

17 return 

18 

19 raise error.AuthenticationError( 

20 "No client_id provided. (HINT: set your client_id using " 

21 '"stripe.client_id = <CLIENT-ID>"). You can find your client_ids ' 

22 "in your Stripe dashboard at " 

23 "https://dashboard.stripe.com/account/applications/settings, " 

24 "after registering your account as a platform. See " 

25 "https://stripe.com/docs/connect/standalone-accounts for details, " 

26 "or email support@stripe.com if you have any questions." 

27 ) 

28 

29 @staticmethod 

30 def authorize_url(express=False, **params): 

31 if express is False: 

32 path = "/oauth/authorize" 

33 else: 

34 path = "/express/oauth/authorize" 

35 

36 OAuth._set_client_id(params) 

37 if "response_type" not in params: 

38 params["response_type"] = "code" 

39 query = urlencode(list(api_requestor._api_encode(params))) 

40 url = connect_api_base + path + "?" + query 

41 return url 

42 

43 @staticmethod 

44 def token(api_key=None, **params): 

45 requestor = api_requestor.APIRequestor( 

46 api_key, api_base=connect_api_base 

47 ) 

48 response, _ = requestor.request("post", "/oauth/token", params, None) 

49 return response.data 

50 

51 @staticmethod 

52 def deauthorize(api_key=None, **params): 

53 requestor = api_requestor.APIRequestor( 

54 api_key, api_base=connect_api_base 

55 ) 

56 OAuth._set_client_id(params) 

57 response, _ = requestor.request( 

58 "post", "/oauth/deauthorize", params, None 

59 ) 

60 return response.data