|
24 | 24 | from Crypto.PublicKey import RSA |
25 | 25 | from Crypto.Signature import PKCS1_v1_5 |
26 | 26 | from oauth2client import client |
| 27 | +from oauth2client.client import _get_application_default_credential_from_file |
27 | 28 | from oauth2client import crypt |
28 | 29 | from oauth2client import service_account |
29 | 30 | import pytz |
@@ -72,8 +73,37 @@ def get_credentials(): |
72 | 73 | return client.GoogleCredentials.get_application_default() |
73 | 74 |
|
74 | 75 |
|
| 76 | +def get_for_service_account_json(json_credentials_path, scope=None): |
| 77 | + """Gets the credentials for a service account with JSON key. |
| 78 | +
|
| 79 | + :type json_credentials_path: string |
| 80 | + :param json_credentials_path: The path to a private key file (this file was |
| 81 | + given to you when you created the service |
| 82 | + account). This file must contain a JSON |
| 83 | + object with a private key and other |
| 84 | + credentials information (downloaded from the |
| 85 | + Google APIs console). |
| 86 | +
|
| 87 | + :type scope: string or tuple of string |
| 88 | + :param scope: The scope against which to authenticate. (Different services |
| 89 | + require different scopes, check the documentation for which |
| 90 | + scope is required for the different levels of access to any |
| 91 | + particular API.) |
| 92 | +
|
| 93 | + :rtype: :class:`oauth2client.client.GoogleCredentials`, |
| 94 | + :class:`oauth2client.service_account._ServiceAccountCredentials` |
| 95 | + :returns: New service account or Google (for a user JSON key file) |
| 96 | + credentials object. |
| 97 | + """ |
| 98 | + credentials = _get_application_default_credential_from_file( |
| 99 | + json_credentials_path) |
| 100 | + if scope is not None: |
| 101 | + credentials = credentials.create_scoped(scope) |
| 102 | + return credentials |
| 103 | + |
| 104 | + |
75 | 105 | def get_for_service_account_p12(client_email, private_key_path, scope=None): |
76 | | - """Gets the credentials for a service account. |
| 106 | + """Gets the credentials for a service account with PKCS12 / p12 key. |
77 | 107 |
|
78 | 108 | .. note:: |
79 | 109 | This method is not used by default, instead :func:`get_credentials` |
|
0 commit comments