Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Signing.singer_email #89

Merged
merged 1 commit into from
Dec 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions google/auth/app_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,8 @@ def with_scopes(self, scopes):
@_helpers.copy_docstring(credentials.Signing)
def sign_bytes(self, message):
return app_identity.sign_blob(message)

@property
@_helpers.copy_docstring(credentials.Signing)
def signer_email(self):
return self.service_account_email

This comment was marked as spam.

This comment was marked as spam.

7 changes: 7 additions & 0 deletions google/auth/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,10 @@ def sign_bytes(self, message):
# pylint: disable=missing-raises-doc,redundant-returns-doc
# (pylint doesn't recognize that this is abstract)
raise NotImplementedError('Sign bytes must be implemented.')

@abc.abstractproperty
def signer_email(self):
"""Optional[str]: An email address that identifies the signer."""
# pylint: disable=missing-raises-doc
# (pylint doesn't recognize that this is abstract)
raise NotImplementedError('Signer email must be implemented.')
5 changes: 5 additions & 0 deletions google/auth/jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,11 @@ def sign_bytes(self, message):
"""
return self._signer.sign(message)

@property
@_helpers.copy_docstring(credentials.Signing)
def signer_email(self):
return self._issuer

def before_request(self, request, method, url, headers):
"""Performs credential-specific before request logic.

Expand Down
5 changes: 5 additions & 0 deletions google/oauth2/service_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,8 @@ def refresh(self, request):
@_helpers.copy_docstring(credentials.Signing)
def sign_bytes(self, message):
return self._signer.sign(message)

@property
@_helpers.copy_docstring(credentials.Signing)
def signer_email(self):
return self._service_account_email
3 changes: 3 additions & 0 deletions tests/oauth2/test_service_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ def test_sign_bytes(self):
signature = self.credentials.sign_bytes(to_sign)
assert crypt.verify_signature(to_sign, signature, PUBLIC_CERT_BYTES)

def test_signer_email(self):
assert self.credentials.signer_email == self.SERVICE_ACCOUNT_EMAIL

def test_create_scoped(self):
scopes = ['email', 'profile']
credentials = self.credentials.with_scopes(scopes)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_app_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,7 @@ def test_sign_bytes(self, app_identity_mock):

assert signature == mock.sentinel.signature
app_identity_mock.sign_blob.assert_called_with(to_sign)

def test_signer_email(self, app_identity_mock):
credentials = app_engine.Credentials()
assert credentials.signer_email == credentials.service_account_email
4 changes: 4 additions & 0 deletions tests/test_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ def test_sign_bytes(self):
signature = self.credentials.sign_bytes(to_sign)
assert crypt.verify_signature(to_sign, signature, PUBLIC_CERT_BYTES)

def test_signer_email(self):
assert (self.credentials.signer_email ==
SERVICE_ACCOUNT_INFO['client_email'])

def _verify_token(self, token):
payload = jwt.decode(token, PUBLIC_CERT_BYTES)
assert payload['iss'] == self.SERVICE_ACCOUNT_EMAIL
Expand Down