Skip to content

Commit

Permalink
Add jwt enhacer to remove undesire char (#36)
Browse files Browse the repository at this point in the history
* Added JWT Enhancer

* Moke code compatible

* Added jwt package in service and move jwt services in that package
  • Loading branch information
Harsh3305 authored Jun 29, 2023
1 parent 31e55aa commit 3719133
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.hrv.mart.apigatewayadmin.config.jwt

import com.hrv.mart.apigatewayadmin.service.JWTService
import com.hrv.mart.apigatewayadmin.service.jwt.JWTService
import org.springframework.security.authentication.ReactiveAuthenticationManager
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
import org.springframework.security.core.Authentication
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.hrv.mart.apigatewayadmin.controller

import com.hrv.mart.apigatewayadmin.service.AuthService
import com.hrv.mart.apigatewayadmin.service.JWTService
import com.hrv.mart.apigatewayadmin.service.jwt.JWTService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.server.reactive.ServerHttpResponse
import org.springframework.web.bind.annotation.PostMapping
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hrv.mart.apigatewayadmin.service

import com.hrv.mart.apigatewayadmin.service.jwt.JWTEnhancer
import com.hrv.mart.authlibrary.repository.AuthRepository
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.server.reactive.ServerHttpResponse
Expand All @@ -15,7 +16,7 @@ class AuthService (
fun login(appwriteJWT: String, response: ServerHttpResponse) =
authRepository
.createAdminAuth(
jwt = appwriteJWT.replace(specialCharCode.toChar().toString(), ""),
jwt = JWTEnhancer.enhanceJWT(appwriteJWT),
response = response
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.hrv.mart.apigatewayadmin.service.jwt

class JWTEnhancer {

companion object {
private const val specialCharCode= 34
fun enhanceJWT(jwt: String) =
jwt.replace(specialCharCode.toChar().toString(), "")
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hrv.mart.apigatewayadmin.service
package com.hrv.mart.apigatewayadmin.service.jwt

import io.jsonwebtoken.Jwts
import io.jsonwebtoken.SignatureAlgorithm
Expand Down Expand Up @@ -47,6 +47,6 @@ class JWTService (
Jwts.parserBuilder()
.setSigningKey(keyPair.public)
.build()
.parseClaimsJws(jwt)
.parseClaimsJws(JWTEnhancer.enhanceJWT(jwt))

}

0 comments on commit 3719133

Please sign in to comment.