本文整理汇总了Python中oauth2client.clientsecrets.InvalidClientSecretsError方法的典型用法代码示例。如果您正苦于以下问题:Python clientsecrets.InvalidClientSecretsError方法的具体用法?Python clientsecrets.InvalidClientSecretsError怎么用?Python clientsecrets.InvalidClientSecretsError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth2client.clientsecrets
的用法示例。
在下文中一共展示了clientsecrets.InvalidClientSecretsError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_string_not_configured_type_web
# 需要导入模块: from oauth2client import clientsecrets [as 别名]
# 或者: from oauth2client.clientsecrets import InvalidClientSecretsError [as 别名]
def test_string_not_configured_type_web(self):
string_props = clientsecrets.VALID_CLIENT[
clientsecrets.TYPE_WEB]['string']
self.assertTrue('client_id' in string_props)
clientsecrets_dict = {
clientsecrets.TYPE_WEB: {
'client_id': '[[template]]',
'client_secret': 'seekrit',
'redirect_uris': None,
'auth_uri': None,
'token_uri': None,
},
}
with self.assertRaises(clientsecrets.InvalidClientSecretsError):
clientsecrets._validate_clientsecrets(clientsecrets_dict)
示例2: test_string_not_configured_type_installed
# 需要导入模块: from oauth2client import clientsecrets [as 别名]
# 或者: from oauth2client.clientsecrets import InvalidClientSecretsError [as 别名]
def test_string_not_configured_type_installed(self):
string_props = clientsecrets.VALID_CLIENT[
clientsecrets.TYPE_INSTALLED]['string']
self.assertTrue('client_id' in string_props)
clientsecrets_dict = {
clientsecrets.TYPE_INSTALLED: {
'client_id': '[[template]]',
'client_secret': 'seekrit',
'redirect_uris': None,
'auth_uri': None,
'token_uri': None,
},
}
with self.assertRaises(clientsecrets.InvalidClientSecretsError):
clientsecrets._validate_clientsecrets(clientsecrets_dict)
示例3: __init__
# 需要导入模块: from oauth2client import clientsecrets [as 别名]
# 或者: from oauth2client.clientsecrets import InvalidClientSecretsError [as 别名]
def __init__(self, filename, scope, message=None, cache=None, **kwargs):
"""Constructor
Args:
filename: string, File name of client secrets.
scope: string or iterable of strings, scope(s) of the credentials
being requested.
message: string, A friendly string to display to the user if the
clientsecrets file is missing or invalid. The message may
contain HTML and will be presented on the web interface
for any method that uses the decorator.
cache: An optional cache service client that implements get() and
set()
methods. See clientsecrets.loadfile() for details.
**kwargs: dict, Keyword arguments are passed along as kwargs to
the OAuth2WebServerFlow constructor.
"""
client_type, client_info = clientsecrets.loadfile(filename,
cache=cache)
if client_type not in (clientsecrets.TYPE_WEB,
clientsecrets.TYPE_INSTALLED):
raise clientsecrets.InvalidClientSecretsError(
"OAuth2Decorator doesn't support this OAuth 2.0 flow.")
constructor_kwargs = dict(kwargs)
constructor_kwargs.update({
'auth_uri': client_info['auth_uri'],
'token_uri': client_info['token_uri'],
'message': message,
})
revoke_uri = client_info.get('revoke_uri')
if revoke_uri is not None:
constructor_kwargs['revoke_uri'] = revoke_uri
super(OAuth2DecoratorFromClientSecrets, self).__init__(
client_info['client_id'], client_info['client_secret'],
scope, **constructor_kwargs)
if message is not None:
self._message = message
else:
self._message = 'Please configure your application for OAuth 2.0.'
示例4: test_with_none
# 需要导入模块: from oauth2client import clientsecrets [as 别名]
# 或者: from oauth2client.clientsecrets import InvalidClientSecretsError [as 别名]
def test_with_none(self):
with self.assertRaises(clientsecrets.InvalidClientSecretsError):
clientsecrets._validate_clientsecrets(None)
示例5: test_with_other_than_one_key
# 需要导入模块: from oauth2client import clientsecrets [as 别名]
# 或者: from oauth2client.clientsecrets import InvalidClientSecretsError [as 别名]
def test_with_other_than_one_key(self):
with self.assertRaises(clientsecrets.InvalidClientSecretsError):
clientsecrets._validate_clientsecrets({})
with self.assertRaises(clientsecrets.InvalidClientSecretsError):
clientsecrets._validate_clientsecrets({'one': 'val', 'two': 'val'})
示例6: test_with_non_dictionary
# 需要导入模块: from oauth2client import clientsecrets [as 别名]
# 或者: from oauth2client.clientsecrets import InvalidClientSecretsError [as 别名]
def test_with_non_dictionary(self):
non_dict = [None]
with self.assertRaises(clientsecrets.InvalidClientSecretsError):
clientsecrets._validate_clientsecrets(non_dict)
示例7: test_missing_required_type_web
# 需要导入模块: from oauth2client import clientsecrets [as 别名]
# 或者: from oauth2client.clientsecrets import InvalidClientSecretsError [as 别名]
def test_missing_required_type_web(self):
required = clientsecrets.VALID_CLIENT[
clientsecrets.TYPE_WEB]['required']
# We will certainly have less than all 5 keys.
self.assertEqual(len(required), 5)
clientsecrets_dict = {
clientsecrets.TYPE_WEB: {'not_required': None},
}
with self.assertRaises(clientsecrets.InvalidClientSecretsError):
clientsecrets._validate_clientsecrets(clientsecrets_dict)
示例8: test_missing_required_type_installed
# 需要导入模块: from oauth2client import clientsecrets [as 别名]
# 或者: from oauth2client.clientsecrets import InvalidClientSecretsError [as 别名]
def test_missing_required_type_installed(self):
required = clientsecrets.VALID_CLIENT[
clientsecrets.TYPE_INSTALLED]['required']
# We will certainly have less than all 5 keys.
self.assertEqual(len(required), 5)
clientsecrets_dict = {
clientsecrets.TYPE_INSTALLED: {'not_required': None},
}
with self.assertRaises(clientsecrets.InvalidClientSecretsError):
clientsecrets._validate_clientsecrets(clientsecrets_dict)
示例9: test_non_existent
# 需要导入模块: from oauth2client import clientsecrets [as 别名]
# 或者: from oauth2client.clientsecrets import InvalidClientSecretsError [as 别名]
def test_non_existent(self):
path = os.path.join(DATA_DIR, 'fake.json')
self.assertFalse(os.path.exists(path))
with self.assertRaises(clientsecrets.InvalidClientSecretsError):
clientsecrets._loadfile(path)
示例10: test_load_by_filename_missing_file
# 需要导入模块: from oauth2client import clientsecrets [as 别名]
# 或者: from oauth2client.clientsecrets import InvalidClientSecretsError [as 别名]
def test_load_by_filename_missing_file(self):
with self.assertRaises(
clientsecrets.InvalidClientSecretsError) as exc_manager:
clientsecrets._loadfile(NONEXISTENT_FILE)
self.assertEquals(exc_manager.exception.args[1], NONEXISTENT_FILE)
self.assertEquals(exc_manager.exception.args[3], errno.ENOENT)
示例11: test_validation
# 需要导入模块: from oauth2client import clientsecrets [as 别名]
# 或者: from oauth2client.clientsecrets import InvalidClientSecretsError [as 别名]
def test_validation(self):
with self.assertRaises(clientsecrets.InvalidClientSecretsError):
clientsecrets.loadfile(INVALID_FILE, cache=self.cache_mock)
示例12: credentials_from_clientsecrets_and_code
# 需要导入模块: from oauth2client import clientsecrets [as 别名]
# 或者: from oauth2client.clientsecrets import InvalidClientSecretsError [as 别名]
def credentials_from_clientsecrets_and_code(filename, scope, code,
message = None,
redirect_uri='postmessage',
http=None,
cache=None,
device_uri=None):
"""Returns OAuth2Credentials from a clientsecrets file and an auth code.
Will create the right kind of Flow based on the contents of the clientsecrets
file or will raise InvalidClientSecretsError for unknown types of Flows.
Args:
filename: string, File name of clientsecrets.
scope: string or iterable of strings, scope(s) to request.
code: string, An authorization code, most likely passed down from
the client
message: string, A friendly string to display to the user if the
clientsecrets file is missing or invalid. If message is provided then
sys.exit will be called in the case of an error. If message in not
provided then clientsecrets.InvalidClientSecretsError will be raised.
redirect_uri: string, this is generally set to 'postmessage' to match the
redirect_uri that the client specified
http: httplib2.Http, optional http instance to use to do the fetch
cache: An optional cache service client that implements get() and set()
methods. See clientsecrets.loadfile() for details.
device_uri: string, OAuth 2.0 device authorization endpoint
Returns:
An OAuth2Credentials object.
Raises:
FlowExchangeError if the authorization code cannot be exchanged for an
access token
UnknownClientSecretsFlowError if the file describes an unknown kind of Flow.
clientsecrets.InvalidClientSecretsError if the clientsecrets file is
invalid.
"""
flow = flow_from_clientsecrets(filename, scope, message=message, cache=cache,
redirect_uri=redirect_uri,
device_uri=device_uri)
credentials = flow.step2_exchange(code, http=http)
return credentials
示例13: flow_from_clientsecrets
# 需要导入模块: from oauth2client import clientsecrets [as 别名]
# 或者: from oauth2client.clientsecrets import InvalidClientSecretsError [as 别名]
def flow_from_clientsecrets(filename, scope, redirect_uri=None,
message=None, cache=None, login_hint=None,
device_uri=None):
"""Create a Flow from a clientsecrets file.
Will create the right kind of Flow based on the contents of the clientsecrets
file or will raise InvalidClientSecretsError for unknown types of Flows.
Args:
filename: string, File name of client secrets.
scope: string or iterable of strings, scope(s) to request.
redirect_uri: string, Either the string 'urn:ietf:wg:oauth:2.0:oob' for
a non-web-based application, or a URI that handles the callback from
the authorization server.
message: string, A friendly string to display to the user if the
clientsecrets file is missing or invalid. If message is provided then
sys.exit will be called in the case of an error. If message in not
provided then clientsecrets.InvalidClientSecretsError will be raised.
cache: An optional cache service client that implements get() and set()
methods. See clientsecrets.loadfile() for details.
login_hint: string, Either an email address or domain. Passing this hint
will either pre-fill the email box on the sign-in form or select the
proper multi-login session, thereby simplifying the login flow.
device_uri: string, URI for device authorization endpoint. For convenience
defaults to Google's endpoints but any OAuth 2.0 provider can be used.
Returns:
A Flow object.
Raises:
UnknownClientSecretsFlowError if the file describes an unknown kind of Flow.
clientsecrets.InvalidClientSecretsError if the clientsecrets file is
invalid.
"""
try:
client_type, client_info = clientsecrets.loadfile(filename, cache=cache)
if client_type in (clientsecrets.TYPE_WEB, clientsecrets.TYPE_INSTALLED):
constructor_kwargs = {
'redirect_uri': redirect_uri,
'auth_uri': client_info['auth_uri'],
'token_uri': client_info['token_uri'],
'login_hint': login_hint,
}
revoke_uri = client_info.get('revoke_uri')
if revoke_uri is not None:
constructor_kwargs['revoke_uri'] = revoke_uri
if device_uri is not None:
constructor_kwargs['device_uri'] = device_uri
return OAuth2WebServerFlow(
client_info['client_id'], client_info['client_secret'],
scope, **constructor_kwargs)
except clientsecrets.InvalidClientSecretsError:
if message:
sys.exit(message)
else:
raise
else:
raise UnknownClientSecretsFlowError(
'This OAuth 2.0 flow is unsupported: %r' % client_type)
示例14: credentials_from_clientsecrets_and_code
# 需要导入模块: from oauth2client import clientsecrets [as 别名]
# 或者: from oauth2client.clientsecrets import InvalidClientSecretsError [as 别名]
def credentials_from_clientsecrets_and_code(filename, scope, code,
message=None,
redirect_uri='postmessage',
http=None,
cache=None,
device_uri=None):
"""Returns OAuth2Credentials from a clientsecrets file and an auth code.
Will create the right kind of Flow based on the contents of the
clientsecrets file or will raise InvalidClientSecretsError for unknown
types of Flows.
Args:
filename: string, File name of clientsecrets.
scope: string or iterable of strings, scope(s) to request.
code: string, An authorization code, most likely passed down from
the client
message: string, A friendly string to display to the user if the
clientsecrets file is missing or invalid. If message is
provided then sys.exit will be called in the case of an error.
If message in not provided then
clientsecrets.InvalidClientSecretsError will be raised.
redirect_uri: string, this is generally set to 'postmessage' to match
the redirect_uri that the client specified
http: httplib2.Http, optional http instance to use to do the fetch
cache: An optional cache service client that implements get() and set()
methods. See clientsecrets.loadfile() for details.
device_uri: string, OAuth 2.0 device authorization endpoint
Returns:
An OAuth2Credentials object.
Raises:
FlowExchangeError: if the authorization code cannot be exchanged for an
access token
UnknownClientSecretsFlowError: if the file describes an unknown kind
of Flow.
clientsecrets.InvalidClientSecretsError: if the clientsecrets file is
invalid.
"""
flow = flow_from_clientsecrets(filename, scope, message=message,
cache=cache, redirect_uri=redirect_uri,
device_uri=device_uri)
credentials = flow.step2_exchange(code, http=http)
return credentials
示例15: credentials_from_clientsecrets_and_code
# 需要导入模块: from oauth2client import clientsecrets [as 别名]
# 或者: from oauth2client.clientsecrets import InvalidClientSecretsError [as 别名]
def credentials_from_clientsecrets_and_code(filename, scope, code,
message=None,
redirect_uri='postmessage',
http=None,
cache=None,
device_uri=None):
"""Returns OAuth2Credentials from a clientsecrets file and an auth code.
Will create the right kind of Flow based on the contents of the
clientsecrets file or will raise InvalidClientSecretsError for unknown
types of Flows.
Args:
filename: string, File name of clientsecrets.
scope: string or iterable of strings, scope(s) to request.
code: string, An authorization code, most likely passed down from
the client
message: string, A friendly string to display to the user if the
clientsecrets file is missing or invalid. If message is
provided then sys.exit will be called in the case of an error.
If message in not provided then
clientsecrets.InvalidClientSecretsError will be raised.
redirect_uri: string, this is generally set to 'postmessage' to match
the redirect_uri that the client specified
http: httplib2.Http, optional http instance to use to do the fetch
cache: An optional cache service client that implements get() and set()
methods. See clientsecrets.loadfile() for details.
device_uri: string, OAuth 2.0 device authorization endpoint
pkce: boolean, default: False, Generate and include a "Proof Key
for Code Exchange" (PKCE) with your authorization and token
requests. This adds security for installed applications that
cannot protect a client_secret. See RFC 7636 for details.
code_verifier: bytestring or None, default: None, parameter passed
as part of the code exchange when pkce=True. If
None, a code_verifier will automatically be
generated as part of step1_get_authorize_url(). See
RFC 7636 for details.
Returns:
An OAuth2Credentials object.
Raises:
FlowExchangeError: if the authorization code cannot be exchanged for an
access token
UnknownClientSecretsFlowError: if the file describes an unknown kind
of Flow.
clientsecrets.InvalidClientSecretsError: if the clientsecrets file is
invalid.
"""
flow = flow_from_clientsecrets(filename, scope, message=message,
cache=cache, redirect_uri=redirect_uri,
device_uri=device_uri)
credentials = flow.step2_exchange(code, http=http)
return credentials