Skip to content

Commit

Permalink
Add Signing.singer_email (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Wayne Parrott authored Dec 2, 2016
1 parent 56fe71a commit 4c883f0
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 0 deletions.
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
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

0 comments on commit 4c883f0

Please sign in to comment.