use of com.auth0.android.jwt.JWT in project micro-service-examples by jetlinks.
the class JwtAuthSupplier method preHandle.
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String token = request.getHeader(HttpHeaders.AUTHORIZATION);
if (StringUtils.isEmpty(token) || !token.startsWith("jwt")) {
return true;
}
JWTVerifier verifier = jwt.createVerifier();
DecodedJWT jwt = verifier.verify(token.substring(4));
ContextUtils.currentContext().put(Authentication.class, factory.create().json(jwt.getSubject()).build());
return true;
}
use of com.auth0.android.jwt.JWT in project TCSS450-Mobile-App by TCSS450-Team7-MobileApp.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mMainActivity = this;
MainActivityArgs args = MainActivityArgs.fromBundle(getIntent().getExtras());
// Import com.auth0.android.jwt.JWT
JWT jwt = new JWT(args.getJwt());
// created on the web service.
if (!jwt.isExpired(0)) {
jwt = new JWT(args.getJwt());
}
new ViewModelProvider(this, new UserInfoViewModel.UserInfoViewModelFactory(args.getEmail(), jwt.toString(), args.getFirst(), args.getLast(), args.getNick(), args.getId())).get(UserInfoViewModel.class);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
// Make sure the new statements go BELOW setContentView
BottomNavigationView navView = findViewById(R.id.nav_view);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
mAppBarConfiguration = new AppBarConfiguration.Builder(R.id.navigation_message, R.id.navigation_home, R.id.navigation_weather).build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
NavigationUI.setupWithNavController(navView, navController);
mNewMessageModel = new ViewModelProvider(this).get(NewMessageCountViewModel.class);
navController.addOnDestinationChangedListener((controller, destination, arguments) -> {
if (destination.getId() == R.id.navigation_message) {
// When the user navigates to the chats page, reset the new message count.
// This will need some extra logic for your project as it should have
// multiple chat rooms.
mNewMessageModel.reset();
}
});
mNewMessageModel.addMessageCountObserver(this, count -> {
BadgeDrawable badge = binding.navView.getOrCreateBadge(R.id.navigation_message);
badge.setMaxCharacterCount(2);
if (count > 0) {
// new messages! update and show the notification badge.
badge.setNumber(count);
badge.setVisible(true);
} else {
// user did some action to clear the new messages, remove the badge
badge.clearNumber();
badge.setVisible(false);
}
});
}
use of com.auth0.android.jwt.JWT in project bitrxc-server by bitrxc.
the class TokenManager method createTokenForAdmin.
// 管理员端token生成
public String createTokenForAdmin(String phone) {
Date expirationTime = new Date(System.currentTimeMillis() + this.tokenExpiration);
// 私钥及加密算法
Algorithm algorithm = Algorithm.HMAC256(tokenSignKey);
// 设置头信息
Map<String, Object> header = new HashMap<>();
header.put("typ", "JWT");
header.put("alg", "HS256");
return JWT.create().withHeader(header).withExpiresAt(expirationTime).withClaim("phone", phone).sign(algorithm);
}
use of com.auth0.android.jwt.JWT in project tutorials by jhkim105.
the class JwtAuthenticationTokenService method parseToken.
public AuthUser parseToken(String token) {
checkToken(token);
try {
DecodedJWT jwt = JWT.decode(token);
String id = jwt.getClaim("id").asString();
String username = jwt.getClaim("username").asString();
String authority = jwt.getClaim("authority").asString();
AuthUser authUser = AuthUser.builder().id(id).username(username).authority(authority).build();
return authUser;
} catch (JWTDecodeException ex) {
throw new RuntimeException(ex);
}
}
use of com.auth0.android.jwt.JWT in project study by bage2014.
the class JWTTest method main.
public static void main(String[] args) throws IllegalArgumentException, UnsupportedEncodingException {
// jjwt();
String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c";
try {
Algorithm algorithm = Algorithm.HMAC256("your-256-bit-secret");
// Algorithm algorithm = Algorithm.HMAC256("your-256-bit-secret".getBytes("UTF-8"));
JWTVerifier verifier = JWT.require(algorithm).build();
DecodedJWT jwt = verifier.verify(token);
System.out.println(jwt);
} catch (JWTVerificationException exception) {
// Invalid signature/claims
exception.printStackTrace();
}
}
Aggregations