Skip to content

Commit

Permalink
Add app_engine.Signer (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Wayne Parrott authored Dec 14, 2016
1 parent fc16929 commit 256d2bf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
31 changes: 27 additions & 4 deletions google/auth/app_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Google App Engine standard environment credentials.
"""Google App Engine standard environment support.
This module provides authentication for application running on App Engine in
the standard environment using the `App Identity API`_.
This module provides authentication and signing for applications running on App
Engine in the standard environment using the `App Identity API`_.
.. _App Identity API:
Expand All @@ -33,6 +33,29 @@
app_identity = None


class Signer(object):
"""Signs messages using the App Engine app identity service.
This can be used in place of :class:`google.auth.crypt.Signer` when
running in the App Engine standard environment.
"""
def __init__(self):
self.key_id = None

@staticmethod
def sign(message):
"""Signs a message.
Args:
message (Union[str, bytes]): The message to be signed.
Returns:
bytes: The signature of the message.
"""
message = _helpers.to_bytes(message)
return app_identity.sign_blob(message)


def get_project_id():
"""Gets the project ID for the current App Engine application.
Expand Down Expand Up @@ -109,7 +132,7 @@ def with_scopes(self, scopes):

@_helpers.copy_docstring(credentials.Signing)
def sign_bytes(self, message):
return app_identity.sign_blob(message)
return Signer().sign(message)

@property
@_helpers.copy_docstring(credentials.Signing)
Expand Down
2 changes: 1 addition & 1 deletion google/auth/crypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def sign(self, message):
message (Union[str, bytes]): The message to be signed.
Returns:
bytes: The signature of the message for the given key.
bytes: The signature of the message.
"""
message = _helpers.to_bytes(message)
return rsa.pkcs1.sign(message, self._key, 'SHA-256')
Expand Down

0 comments on commit 256d2bf

Please # to comment.