Skip to content

Commit 6814718

Browse files
author
zihluwang
committed
feat: added predefined constants
1 parent b1dbc1c commit 6814718

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (C) 2024-2025 OnixByte.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
*
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.onixbyte.jwt.constant;
19+
20+
public final class HeaderClaims {
21+
22+
/**
23+
* Private constructor to prevent instantiation of this utility class.
24+
*/
25+
private HeaderClaims() {
26+
}
27+
28+
/**
29+
* The algorithm used to sign a JWT.
30+
*/
31+
public static final String ALGORITHM = "alg";
32+
33+
/**
34+
* The content type of the JWT.
35+
*/
36+
public static final String CONTENT_TYPE = "cty";
37+
38+
/**
39+
* The media type of the JWT.
40+
*/
41+
public static final String TYPE = "typ";
42+
43+
/**
44+
* The key ID of a JWT used to specify the key for signature validation.
45+
*/
46+
public static final String KEY_ID = "kid";
47+
48+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (C) 2024-2025 OnixByte.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
*
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package com.onixbyte.jwt.constant;
19+
20+
import java.util.List;
21+
22+
/**
23+
*
24+
*/
25+
public final class RegisteredClaims {
26+
27+
/**
28+
* Private constructor to prevent instantiation of this utility class.
29+
*/
30+
private RegisteredClaims() {
31+
}
32+
33+
/**
34+
* The "iss" (issuer) claim identifies the principal that issued the JWT.
35+
* Refer RFC 7529 <a href="https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.1">Section 4.1.1</a>
36+
*/
37+
public static final String ISSUER = "iss";
38+
39+
/**
40+
* The "sub" (subject) claim identifies the principal that is the subject of the JWT.
41+
* Refer RFC 7529 <a href="https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.2">Section 4.1.2</a>
42+
*/
43+
public static final String SUBJECT = "sub";
44+
45+
/**
46+
* The "aud" (audience) claim identifies the recipients that the JWT is intended for.
47+
* Refer RFC 7529 <a href="https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.3">Section 4.1.3</a>
48+
*/
49+
public static final String AUDIENCE = "aud";
50+
51+
/**
52+
* The "exp" (expiration time) claim identifies the expiration time on or after which the JWT MUST NOT be
53+
* accepted for processing.
54+
* Refer RFC 7529 <a href="https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.4">Section 4.1.4</a>
55+
*/
56+
public static final String EXPIRES_AT = "exp";
57+
58+
/**
59+
* The "nbf" (not before) claim identifies the time before which the JWT MUST NOT be accepted for processing.
60+
* Refer RFC 7529 <a href="https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.5">Section 4.1.5</a>
61+
*/
62+
public static final String NOT_BEFORE = "nbf";
63+
64+
/**
65+
* The "iat" (issued at) claim identifies the time at which the JWT was issued.
66+
* Refer RFC 7529 <a href="https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.6">Section 4.1.6</a>
67+
*/
68+
public static final String ISSUED_AT = "iat";
69+
70+
/**
71+
* The "jti" (JWT ID) claim provides a unique identifier for the JWT.
72+
* Refer RFC 7529 <a href="https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.7">Section 4.1.7</a>
73+
*/
74+
public static final String TOKEN_ID = "jti";
75+
76+
public static final List<String> VALUES = List.of(ISSUER, SUBJECT, AUDIENCE, EXPIRES_AT, NOT_BEFORE, ISSUED_AT, TOKEN_ID);
77+
78+
}

0 commit comments

Comments
 (0)