@@ -34,7 +34,8 @@ public class PushService {
34
34
private String gcmApiKey ;
35
35
36
36
/**
37
- * Subject used in the JWT payload (for VAPID)
37
+ * Subject used in the JWT payload (for VAPID). When left as null, then no subject will be used
38
+ * (RFC-8292 2.1 says that it is optional)
38
39
*/
39
40
private String subject ;
40
41
@@ -55,15 +56,23 @@ public PushService(String gcmApiKey) {
55
56
this .gcmApiKey = gcmApiKey ;
56
57
}
57
58
58
- public PushService (KeyPair keyPair , String subject ) {
59
+ public PushService (KeyPair keyPair ) {
59
60
this .publicKey = keyPair .getPublic ();
60
61
this .privateKey = keyPair .getPrivate ();
62
+ }
63
+
64
+ public PushService (KeyPair keyPair , String subject ) {
65
+ this (keyPair );
61
66
this .subject = subject ;
62
67
}
63
68
64
- public PushService (String publicKey , String privateKey , String subject ) throws GeneralSecurityException {
69
+ public PushService (String publicKey , String privateKey ) throws GeneralSecurityException {
65
70
this .publicKey = Utils .loadPublicKey (publicKey );
66
71
this .privateKey = Utils .loadPrivateKey (privateKey );
72
+ }
73
+
74
+ public PushService (String publicKey , String privateKey , String subject ) throws GeneralSecurityException {
75
+ this (publicKey , privateKey );
67
76
this .subject = subject ;
68
77
}
69
78
@@ -226,7 +235,9 @@ public HttpPost preparePost(Notification notification, Encoding encoding) throws
226
235
JwtClaims claims = new JwtClaims ();
227
236
claims .setAudience (notification .getOrigin ());
228
237
claims .setExpirationTimeMinutesInTheFuture (12 * 60 );
229
- claims .setSubject (subject );
238
+ if (subject != null ) {
239
+ claims .setSubject (subject );
240
+ }
230
241
231
242
JsonWebSignature jws = new JsonWebSignature ();
232
243
jws .setHeader ("typ" , "JWT" );
0 commit comments