|
52 | 52 | import google.auth.credentials |
53 | 53 |
|
54 | 54 |
|
55 | | -_DEFAULT_TOKEN_LIFETIME_SECS = 3600 # 1 hour in sections |
56 | | -_CLOCK_SKEW_SECS = 300 # 5 minutes in seconds |
| 55 | +_DEFAULT_TOKEN_LIFETIME_SECS = 3600 # 1 hour in seconds |
57 | 56 |
|
58 | 57 |
|
59 | 58 | def encode(signer, payload, header=None, key_id=None): |
@@ -161,21 +160,25 @@ def _verify_iat_and_exp(payload): |
161 | 160 | """ |
162 | 161 | now = _helpers.datetime_to_secs(_helpers.utcnow()) |
163 | 162 |
|
164 | | - # Make sure the iat and exp claims are present |
| 163 | + # Make sure the iat and exp claims are present. |
165 | 164 | for key in ('iat', 'exp'): |
166 | 165 | if key not in payload: |
167 | 166 | raise ValueError( |
168 | 167 | 'Token does not contain required claim {}'.format(key)) |
169 | 168 |
|
170 | | - # Make sure the token wasn't issued in the future |
| 169 | + # Make sure the token wasn't issued in the future. |
171 | 170 | iat = payload['iat'] |
172 | | - earliest = iat - _CLOCK_SKEW_SECS |
| 171 | + # Err on the side of accepting a token that is slightly early to account |
| 172 | + # for clock skew. |
| 173 | + earliest = iat - _helpers.CLOCK_SKEW_SECS |
173 | 174 | if now < earliest: |
174 | 175 | raise ValueError('Token used too early, {} < {}'.format(now, iat)) |
175 | 176 |
|
176 | | - # Make sure the token wasn't issue in the past |
| 177 | + # Make sure the token wasn't issued in the past. |
177 | 178 | exp = payload['exp'] |
178 | | - latest = exp + _CLOCK_SKEW_SECS |
| 179 | + # Err on the side of accepting a token that is slightly out of date |
| 180 | + # to account for clow skew. |
| 181 | + latest = exp + _helpers.CLOCK_SKEW_SECS |
179 | 182 | if latest < now: |
180 | 183 | raise ValueError('Token expired, {} < {}'.format(latest, now)) |
181 | 184 |
|
|
0 commit comments