{"id":36418941,"url":"https://github.com/phuongbv00/jauth-utils","last_synced_at":"2026-01-11T17:01:53.280Z","repository":{"id":42003874,"uuid":"372068116","full_name":"phuongbv00/jauth-utils","owner":"phuongbv00","description":"JAuth Utils is a Java library that simplifies JWT authentication wrap jjwt and supports Spring Boot","archived":false,"fork":false,"pushed_at":"2022-07-08T12:14:26.000Z","size":58,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-11T14:46:25.955Z","etag":null,"topics":["authentication","java","spring-boot"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phuongbv00.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-29T20:56:53.000Z","updated_at":"2022-01-01T10:48:20.000Z","dependencies_parsed_at":"2022-08-12T02:01:06.400Z","dependency_job_id":null,"html_url":"https://github.com/phuongbv00/jauth-utils","commit_stats":null,"previous_names":["phuongbv00/jauth-utils","censodev/jauth-utils"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/phuongbv00/jauth-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phuongbv00%2Fjauth-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phuongbv00%2Fjauth-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phuongbv00%2Fjauth-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phuongbv00%2Fjauth-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phuongbv00","download_url":"https://codeload.github.com/phuongbv00/jauth-utils/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phuongbv00%2Fjauth-utils/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28314260,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-11T14:58:17.114Z","status":"ssl_error","status_checked_at":"2026-01-11T14:55:53.580Z","response_time":60,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["authentication","java","spring-boot"],"created_at":"2026-01-11T17:01:53.216Z","updated_at":"2026-01-11T17:01:53.272Z","avatar_url":"https://github.com/phuongbv00.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JAuth Utils [Deprecated]\n**This library is deprecated, recommend using [JAuth Lib](https://github.com/censodev/jauth-lib)**\n## 1. Introduction\nJAuth Utils is a Java library that simplifies JWT authentication wrap [jjwt](https://github.com/jwtk/jjwt) and supports Spring Boot.\n\n## 2. Prerequisites\n* Java 8\n* Maven 3\n\n## 3. Installation\n### Maven\n```\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.github.censodev\u003c/groupId\u003e\n    \u003cartifactId\u003ejauth-utils\u003c/artifactId\u003e\n    \u003cversion\u003e3.0.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n### Gradle\n```\nimplementation 'io.github.censodev:jauth-utils:3.0.1'\n```\n\n## 4. Usages\n### 4.1. Define Authenticatable entity\n```java\nclass User implements Credential {\n    private String name = \"name\";\n\n    // Getters, setters ...\n\n    @Override\n    public String getSubject() {\n        return \"subject\";\n    }\n\n    @Override\n    public String getUsername() {\n        return \"usn\";\n    }\n\n    @Override\n    public List\u003cString\u003e getAuthorities() {\n        // must use modifiable list\n        return new ArrayList\u003c\u003e(Arrays.asList(\"role_a\", \"role_b\"));\n    }\n}\n```\n### 4.2. Initiate TokenProvider\n```java\n// With default config\nTokenProvider tokenProvider = new TokenProvider();\n\n// With builder\nTokenProvider tokenProvider = TokenProvider.builder()\n        .expireInMillisecond(3_600_000)\n        .refreshTokenExpireInMillisecond(86_400_000)\n        .secret(\"qwertyuiopasdfghjklzxcvbnm\")\n        .build();\n```\n### 4.3. Generate tokens\n```java\nString accessToken = tokenProvider.generateAccessToken(new User());\nString refreshToken = tokenProvider.generateRefreshToken(new User());\n```\n### 4.4. Get credential from token\n```java\nUser u = tokenProvider.getCredential(token, User.class);\n```\n### 4.5. Validate token\n```java\ntry {\n    tokenProvider.validateToken(token);\n} catch (MalformedJwtException e) {\n    e.printStackTrace();\n} catch (ExpiredJwtException e) {\n    e.printStackTrace();\n} catch (UnsupportedJwtException e) {\n    e.printStackTrace();\n} catch (IllegalArgumentException e) {\n    e.printStackTrace();\n} catch (SignatureException e) {\n    e.printStackTrace();\n}\n```\n### 4.6. Spring Boot filter\n#### 4.6.1. Initiate filter\n```java\nSpringAuthenticationFilter\u003cUser\u003e filter = new SpringAuthenticationFilter\u003c\u003e(tokenProvider, User.class);\n\n// with filter hook\nAuthenticationFilterHook hook = new AuthenticationFilterHook() {\n    @Override\n    public void beforeValidate(TokenProvider tokenProvider, String token) {\n        // do something before validate token\n    }\n    \n    @Override\n    public void afterValidateWell(Credential credential) {\n        // do something after validate token successfully\n    }\n    \n    @Override\n    public void afterValidateFailed(JwtException ex) {\n        // do something after validate token failed\n    }\n\n    @Override\n    public void onError(Exception ex) {\n        // do something when unexpected errors occur\n    }\n};\nSpringAuthenticationFilter\u003cUser\u003e filter = new SpringAuthenticationFilter\u003c\u003e(tokenProvider, User.class, hook);\n```\n#### 4.6.2. Configure security bean\n```java\n@EnableWebSecurity\npublic class SecurityConfig extends WebSecurityConfigurerAdapter {\n    @Override\n    protected void configure(HttpSecurity http) throws Exception {\n        http\n                .csrf().disable()\n                .cors()\n                    .and()\n                .addFilterBefore(springAuthenticationFilter, UsernamePasswordAuthenticationFilter.class)\n                .authorizeRequests()\n                        .antMatchers(\n                                \"/api/auth/**\"\n                        ).permitAll()\n                .anyRequest().authenticated();\n    }\n\n    @Bean\n    public TokenProvider tokenProvider() {\n        return TokenProvider.builder()\n                .expireInMillisecond(3_600_000)\n                .refreshTokenExpireInMillisecond(86_400_000)\n                .secret(\"qwertyuiopasdfghjklzxcvbnm\")\n                .build();\n    }\n}\n```\n#### 4.6.3. Get credential from security context\n```java\nOptional\u003cUser\u003e u = Optional.ofNullable((User) SecurityContextHolder.getContext().getAuthentication().getCredential());\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphuongbv00%2Fjauth-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphuongbv00%2Fjauth-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphuongbv00%2Fjauth-utils/lists"}