Add app_engine.Signer (#97)
diff --git a/google/auth/app_engine.py b/google/auth/app_engine.py
index 608651d..846bcec 100644
--- a/google/auth/app_engine.py
+++ b/google/auth/app_engine.py
@@ -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:
@@ -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.
@@ -109,7 +132,7 @@
@_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)