本文整理汇总了Java中com.auth0.jwt.exceptions.JWTCreationException类的典型用法代码示例。如果您正苦于以下问题:Java JWTCreationException类的具体用法?Java JWTCreationException怎么用?Java JWTCreationException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JWTCreationException类属于com.auth0.jwt.exceptions包,在下文中一共展示了JWTCreationException类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: signToken
import com.auth0.jwt.exceptions.JWTCreationException; //导入依赖的package包/类
private String signToken(User user) {
try {
Algorithm algorithm = Algorithm.HMAC256(Constants.JWT_TOKEN_KEY);
Date expirationDate = Date.from(ZonedDateTime.now().plusHours(24).toInstant());
Date issuedAt = Date.from(ZonedDateTime.now().toInstant());
return JWT.create()
.withIssuedAt(issuedAt)
.withExpiresAt(expirationDate)
.withClaim("userId", user.getId())
.withIssuer("jwtauth")
.sign(algorithm);
} catch (UnsupportedEncodingException | JWTCreationException e) {
LOGGER.error(e.getMessage(), e);
}
return null;
}
开发者ID:Petrakus,项目名称:java-jwt-auth,代码行数:17,代码来源:RESTService.java
示例2: generateFrom
import com.auth0.jwt.exceptions.JWTCreationException; //导入依赖的package包/类
@Override
public String generateFrom(LogInData userData) {
try {
return JWT.create()
.withIssuer(config.getString(ServerVariable.JWT_ISSUER))
.withIssuedAt(new Date())
.withClaim(EMAIL_CLAIM, userData.getEmail())
.sign(getAlgorithm());
} catch (UnsupportedEncodingException | JWTCreationException ex) {
throw new BusinessLogicException(new String[]{BAD_LOGIN});
}
}
开发者ID:VendingOnTime,项目名称:server-vot,代码行数:13,代码来源:JWTTokenGenerator.java
示例3: JWTCreator
import com.auth0.jwt.exceptions.JWTCreationException; //导入依赖的package包/类
private JWTCreator(Algorithm algorithm, Map<String, Object> headerClaims, Map<String, Object> payloadClaims) throws JWTCreationException {
this.algorithm = algorithm;
try {
ObjectMapper mapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addSerializer(ClaimsHolder.class, new PayloadSerializer());
mapper.registerModule(module);
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
headerJson = mapper.writeValueAsString(headerClaims);
payloadJson = mapper.writeValueAsString(new ClaimsHolder(payloadClaims));
} catch (JsonProcessingException e) {
throw new JWTCreationException("Some of the Claims couldn't be converted to a valid JSON format.", e);
}
}
开发者ID:GJWT,项目名称:javaOIDCMsg,代码行数:15,代码来源:JWTCreator.java
示例4: createJwtTokenForUserId
import com.auth0.jwt.exceptions.JWTCreationException; //导入依赖的package包/类
/**
* Creates a JWT token using a User ID.
* @param id User ID.
* @return The JWT Token.
*/
public static String createJwtTokenForUserId(String id) {
try {
return JWT.create()
.withIssuer(issuer)
.withExpiresAt(Date.from(Instant.ofEpochMilli(System.currentTimeMillis() + 1000 * 3600)))
.withClaim("userId", id)
.sign(algorithm);
} catch(JWTCreationException e) {
throw new RuntimeException(e);
}
}
开发者ID:melchor629,项目名称:agendamlgr,代码行数:17,代码来源:TokensUtils.java
示例5: generateToken
import com.auth0.jwt.exceptions.JWTCreationException; //导入依赖的package包/类
public String generateToken(String inbox) {
try {
return JWT.create()
.withIssuer("Wallraff")
.withClaim("inbox", inbox)
.sign(algorithm);
} catch (JWTCreationException exception) {
//Invalid Signing configuration / Couldn't convert Claims.
}
return null;
}
开发者ID:Stubmarine,项目名称:stubmarine,代码行数:13,代码来源:SendGridTokenGenerator.java
示例6: sign
import com.auth0.jwt.exceptions.JWTCreationException; //导入依赖的package包/类
/**
* Creates a new JWT and signs is with the given algorithm
*
* @param algorithm used to sign the JWT
* @return a new JWT token
* @throws IllegalArgumentException if the provided algorithm is null.
* @throws JWTCreationException if the claims could not be converted to a valid JSON or there was a problem with the signing key.
*/
public String sign(Algorithm algorithm) throws IllegalArgumentException, JWTCreationException {
if (algorithm == null) {
throw new IllegalArgumentException("The Algorithm cannot be null.");
}
headerClaims.put(PublicClaims.ALGORITHM, algorithm.getName());
headerClaims.put(PublicClaims.TYPE, "JWT");
String signingKeyId = algorithm.getSigningKeyId();
if (signingKeyId != null) {
withKeyId(signingKeyId);
}
return new JWTCreator(algorithm, headerClaims, payloadClaims).sign();
}
开发者ID:auth0,项目名称:java-jwt,代码行数:21,代码来源:JWTCreator.java
注:本文中的com.auth0.jwt.exceptions.JWTCreationException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论