• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JWTCreationException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HashingInputStream类代码示例发布时间:2022-05-22
下一篇:
Java SnmpOidTable类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap