diff options
author | Vitaly Takmazov | 2023-01-04 03:37:05 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-01-04 03:37:05 +0300 |
commit | 086d9a7625bfc5a386f5b1028d364fb546c2fa9d (patch) | |
tree | 54db8116fa0eaa40e5617d17545e62148b8c608f /src/main/java/com/juick/KeystoreManager.java | |
parent | aa9240e5431c5ee81f3d25d6481c66c445d11711 (diff) |
JWT authentication for API
Diffstat (limited to 'src/main/java/com/juick/KeystoreManager.java')
-rw-r--r-- | src/main/java/com/juick/KeystoreManager.java | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/main/java/com/juick/KeystoreManager.java b/src/main/java/com/juick/KeystoreManager.java index d8355941..952cb72c 100644 --- a/src/main/java/com/juick/KeystoreManager.java +++ b/src/main/java/com/juick/KeystoreManager.java @@ -17,7 +17,9 @@ package com.juick; +import com.juick.model.User; import com.juick.www.api.activity.model.objects.Actor; +import io.jsonwebtoken.Jwts; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.Resource; @@ -30,6 +32,9 @@ import java.io.InputStream; import java.security.*; import java.security.cert.Certificate; import java.security.cert.CertificateException; +import java.time.ZonedDateTime; +import java.util.Arrays; +import java.util.Date; public class KeystoreManager { private static final Logger logger = LoggerFactory.getLogger("ActivityPub"); @@ -51,7 +56,7 @@ public class KeystoreManager { } } - private KeyPair getKeyPair() { + public KeyPair getKeyPair() { java.security.Key privateKey; try { privateKey = ks.getKey("1", keystorePassword.toCharArray()); @@ -77,4 +82,11 @@ public class KeystoreManager { String pubkeyPem = person.getPublicKey().getPublicKeyPem(); return Keys.decode(pubkeyPem.getBytes()).getKey(); } + public String generateToken(User user) { + return Jwts.builder() + .setSubject(user.getName()) + .setIssuedAt(Date.from(ZonedDateTime.now().toInstant())) + .signWith(getPrivateKey()) + .compact(); + } } |