Skip to content

Commit 1e214f2

Browse files
riathakkariennae
andauthored
Update generate_self_signed_jwt.py (GoogleCloudPlatform#12592)
* Update generate_self_signed_jwt.py This is a bug fix in response to a listener report. The datetime object needs to return the current time in epoch * fix(iap): refactor to use time and fix conversion JWT claims require that IAT - "This is a timestamp formatted as whole seconds since January 01, 1970, which is a standard UNIX representation of time. The timestamp must be an integer (no decimals) and it must be in UTC." This means using the time module is sufficient --------- Co-authored-by: Jennifer Davis <[email protected]>
1 parent fd9e83f commit 1e214f2

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

iap/generate_self_signed_jwt.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import datetime
1615
import json
16+
import time
1717

1818
import google.auth
1919
from google.cloud import iam_credentials_v1
@@ -35,15 +35,15 @@ def generate_jwt_payload(service_account_email: str, resource_url: str) -> str:
3535
Access the application with the JWT in the Authorization Header.
3636
curl --verbose --header 'Authorization: Bearer SIGNED_JWT' URL
3737
"""
38-
iat = datetime.datetime.now(tz=datetime.timezone.utc)
39-
exp = iat + 3600
38+
now = int(time.time())
39+
4040
return json.dumps(
4141
{
4242
"iss": service_account_email,
4343
"sub": service_account_email,
4444
"aud": resource_url,
45-
"iat": iat,
46-
"exp": exp,
45+
"iat": now,
46+
"exp": now + 3600,
4747
}
4848
)
4949

0 commit comments

Comments
 (0)