Skip to content

Commit 6e4751c

Browse files
committed
Add and document iat issued date claim
1 parent 3f22286 commit 6e4751c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

docs/spec/1.0.0-rc.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ a manifest in JWT (JSON Web Token) format containing the following claims:
4747
| ----------- | ----------- |
4848
| `iss` | [Standard claim](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.1) containing the URL of the backend that issues sponsor manifests |
4949
| `aud` | [Standard claim](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.3) containing one or more URLs of the supported sponsoring platforms |
50+
| `iat` | [Standard claim](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.6) containing the time the manifest was issued at |
5051
| `sub_jwk` | [Standard claim](https://openid.net/specs/openid-connect-core-1_0.html#SelfIssuedResponse) containing the public key (JWK) that can be used to check the signature of issued sponsor manifests |
5152
| `pub` | Custom claim containing the Base64-encoded public key in `sub_jwt` for easier consumption. |
5253

@@ -62,6 +63,7 @@ The following is an example of a sponsorable manifest:
6263
{
6364
"iss": "https://sponsorlink.devlooped.com/",
6465
"aud": "https://github.com/sponsors/devlooped",
66+
"iat": 1696118400,
6567
"pub": "MII...=",
6668
"sub_jwk": {
6769
"e": "AQAB",
@@ -80,10 +82,11 @@ that the sponsorable issuer provides to the sponsor, containing the following cl
8082
| ----------- | ----------- |
8183
| `iss` | The token [issuer](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.1), matching the sponsorable manifest issuer claim |
8284
| `aud` | The [audience](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.3) URL(s) from the sponsorable manifest |
85+
| `iat` | The [time the manifest was issued at](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.6) |
8386
| `sub` | The [subject](https://www.rfc-editor.org/rfc/rfc7519#section-4.1.2) claim, which is the sponsor account (i.e. user GitHub login) |
8487
| `roles` | The sponsoring [roles](https://www.rfc-editor.org/rfc/rfc9068.html#section-7.2.1.1) of the authenticated user (e.g. team, org, user, contrib) |
85-
| `email` | The sponsor's email(s) |
86-
| `exp` | The token's expiration date |
88+
| `email` | The sponsor's email(s) [standard claim](https://openid.net/specs/openid-connect-core-1_0.html#StandardClaims) |
89+
| `exp` | The token's [expiration date](https://www.rfc-editor.org/rfc/rfc7519.html#section-4.1.4) |
8790

8891
{: .note }
8992
> Tools can fetch the sponsorable manifest from `[iss]/jwt` for verification of the sponsor manifest signature.

src/Core/SponsorableManifest.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ public string ToJwt(SigningCredentials? signing = default)
153153
.Concat(Audience.Select(x => new Claim("aud", x)))
154154
.Concat(
155155
[
156+
// See https://www.rfc-editor.org/rfc/rfc7519.html#section-4.1.6
157+
new("iat", Math.Truncate((DateTime.UtcNow - DateTime.UnixEpoch).TotalSeconds).ToString()),
156158
new("client_id", ClientId),
157159
// non-standard claim containing the base64-encoded public key
158160
new("pub", PublicKey),
@@ -191,7 +193,10 @@ public string Sign(IEnumerable<Claim> claims, RsaSecurityKey? key = default, Tim
191193
DateTime.UtcNow.Millisecond,
192194
DateTimeKind.Utc);
193195

194-
var tokenClaims = claims.ToList();
196+
var tokenClaims = claims.Where(x => x.Type != "iat").ToList();
197+
198+
// See https://www.rfc-editor.org/rfc/rfc7519.html#section-4.1.6
199+
tokenClaims.Add(new("iat", Math.Truncate((DateTime.UtcNow - DateTime.UnixEpoch).TotalSeconds).ToString()));
195200

196201
if (tokenClaims.Find(c => c.Type == "iss") is { } issuer)
197202
{

0 commit comments

Comments
 (0)