use of io.vertx.ext.auth.KeyStoreOptions in project vertx-auth by vert-x3.
the class JWTAuthProviderTest method testGenerateNewTokenES256.
@Test
public void testGenerateNewTokenES256() {
authProvider = JWTAuth.create(vertx, new JWTAuthOptions().setKeyStore(new KeyStoreOptions().setPath("es256-keystore.jceks").setPassword("secret")));
String token = authProvider.generateToken(new JsonObject().put("sub", "paulo"), new JWTOptions().setAlgorithm("ES256"));
assertNotNull(token);
JsonObject authInfo = new JsonObject().put("jwt", token);
authProvider.authenticate(authInfo, res -> {
if (res.failed()) {
res.cause().printStackTrace();
fail();
}
assertNotNull(res.result());
testComplete();
});
await();
}
use of io.vertx.ext.auth.KeyStoreOptions in project vertx-auth by vert-x3.
the class AuthJWTExamples method example6.
public void example6(Vertx vertx) {
JWTAuthOptions config = new JWTAuthOptions().setKeyStore(new KeyStoreOptions().setPath("keystore.jceks").setPassword("secret"));
AuthProvider provider = JWTAuth.create(vertx, config);
}
use of io.vertx.ext.auth.KeyStoreOptions in project vertx-auth by vert-x3.
the class AuthJWTExamples method example7.
public void example7(Vertx vertx, String username, String password) {
JWTAuthOptions config = new JWTAuthOptions().setKeyStore(new KeyStoreOptions().setPath("keystore.jceks").setPassword("secret"));
JWTAuth provider = JWTAuth.create(vertx, config);
// on the verify endpoint once you verify the identity of the user by its username/password
if ("paulo".equals(username) && "super_secret".equals(password)) {
String token = provider.generateToken(new JsonObject().put("sub", "paulo"), new JWTOptions());
// now for any request to protected resources you should pass this string in the HTTP header Authorization as:
// Authorization: Bearer <token>
}
}
use of io.vertx.ext.auth.KeyStoreOptions in project vertx-zero by silentbalanceyh.
the class UxJwt method createDirect.
private static JWT createDirect(final JWTAuthOptions config, final Function<String, Buffer> funcBuffer) {
final JWT reference;
final KeyStoreOptions keyStore = config.getKeyStore();
try {
if (keyStore != null) {
final KeyStore ks = KeyStore.getInstance(keyStore.getType());
final Class var5 = JwtAuthProvider.class;
synchronized (JwtAuthProvider.class) {
final Buffer keystore = funcBuffer.apply(keyStore.getPath());
final InputStream in = new ByteArrayInputStream(keystore.getBytes());
Throwable var8 = null;
try {
ks.load(in, keyStore.getPassword().toCharArray());
} catch (final Throwable var20) {
var8 = var20;
throw var20;
} finally {
if (in != null) {
if (var8 != null) {
try {
in.close();
} catch (final Throwable var19) {
var8.addSuppressed(var19);
}
} else {
in.close();
}
}
}
}
reference = new JWT(ks, keyStore.getPassword().toCharArray());
} else {
reference = new JWT();
final List<PubSecKeyOptions> keys = config.getPubSecKeys();
if (keys != null) {
final Iterator var25 = config.getPubSecKeys().iterator();
while (var25.hasNext()) {
final PubSecKeyOptions pubSecKey = (PubSecKeyOptions) var25.next();
if (pubSecKey.isSymmetric()) {
reference.addJWK(new JWK(pubSecKey.getAlgorithm(), pubSecKey.getPublicKey()));
} else {
reference.addJWK(new JWK(pubSecKey.getAlgorithm(), pubSecKey.isCertificate(), pubSecKey.getPublicKey(), pubSecKey.getSecretKey()));
}
}
}
final List<SecretOptions> secrets = config.getSecrets();
if (secrets != null) {
final Iterator var28 = secrets.iterator();
while (var28.hasNext()) {
final SecretOptions secret = (SecretOptions) var28.next();
reference.addSecret(secret.getType(), secret.getSecret());
}
}
}
} catch (IOException | FileSystemException | CertificateException | NoSuchAlgorithmException | KeyStoreException var23) {
throw new _500JwtRuntimeException(UxJwt.class, var23);
}
return reference;
}
use of io.vertx.ext.auth.KeyStoreOptions in project vertx-auth by vert-x3.
the class JWTAuthProviderTest method testGenerateNewTokenForceAlgorithm.
@Test
public void testGenerateNewTokenForceAlgorithm() {
authProvider = JWTAuth.create(vertx, new JWTAuthOptions().setKeyStore(new KeyStoreOptions().setPath("gce.jks").setType("jks").setPassword("notasecret")));
String token = authProvider.generateToken(new JsonObject(), new JWTOptions().setAlgorithm("RS256"));
assertNotNull(token);
// reverse
JsonObject authInfo = new JsonObject().put("jwt", token);
authProvider.authenticate(authInfo, onSuccess(res -> {
assertNotNull(res);
testComplete();
}));
await();
}
Aggregations