Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.
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
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