작성
·
471
0
http://localhost:8888/ecommerce/default 에서는
{
name: "ecommerce",
profiles: [
"default"
],
label: null,
version: "f45bf692a6cb54252ea12041f0aa92a71964a5f7",
state: null,
propertySources: [
{
name: "file:///C:\\Users\\ydj90\\Downloads\\git/file:C:\Users\ydj90\Downloads\git\ecommerce.yml",
source: {
token.expiration_time: 864000000,
gateway.ip: "172.30.1.33",
token.secret: "userToken_token"
}
}
]
}
http://localhost:8888/user-service/default 에서는
{
name: "user-service",
profiles: [
"default"
],
label: null,
version: "f45bf692a6cb54252ea12041f0aa92a71964a5f7",
state: null,
propertySources: [
{
name: "file:///C:\\Users\\ydj90\\Downloads\\git/file:C:\Users\ydj90\Downloads\git\user-service.yml",
source: {
spring.datasource.url: "jdbc:h2:mem:testdb",
spring.datasource.driver-class-name: "org.h2.Driver",
spring.datasource.generate-unique-name: false,
token.expiration_time: 864000000,
gateway.ip: "172.30.1.33",
order_service.url: "http://ORDER-SERVICE/order-service/%s/orders",
spring.datasource.username: "sa",
token.secret: "userToken_token"
}
}
]
}
이와 같이 token.secret이 같은데 왜 subject가 null값이 되는지 이유를 알 수 가 없습니다. login하고 나온 header값을 가지고 bearer에 넣어 인증하는 방식이 아닙니까?
이유를 잘 모르겠습니다.
JWT token is not valid
이게 왜 뜨는지
subject = Jwts.parser().setSigningKey(env.getProperty("token.secret"))
.parseClaimsJws(jwt).getBody()
.getSubject();
여기서 왜 null값으로 값을 반환하는지 이해를 할 수가 없습니다.
답변 4
0
혹시 해결 하셨나요??
저도 토큰 복호화값 null 뜨길래 구글링 해보니
Jwts.parser()
이게 deprecated 되었다고 해서 gradle 버전
implementation io.jsonwebtoken:jjwt:0.9.1
을 아래 세개로 바꾸고
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'
Jwts.parser() -> Jwts.parserBuilder()
로 바꾸니 잘됩니다!!
0
0
env
ApplicationReactiveWebEnvironment {activeProfiles=[], defaultProfiles=[default], propertySources=[MapPropertySource {name='server.ports'}, BootstrapPropertySource {name='bootstrapProperties-configClient'}, BootstrapPropertySource {name='bootstrapProperties-file:///C:\\Users\\ydj90\\Downloads\\git/file:C:\Users\ydj90\Downloads\git\ecommerce.yml'}, ConfigurationPropertySourcesPropertySource {name='configurationProperties'}, MapPropertySource {name='springCloudBusOverridesProperties'}, MapPropertySource {name='gateway-properties'}, PropertiesPropertySource {name='systemProperties'}, OriginAwareSystemEnvironmentPropertySource {name='systemEnvironment'}, RandomValuePropertySource {name='random'}, CachedRandomPropertySource {name='cachedrandom'}, MapPropertySource {name='springCloudClientHostInfo'}, OriginTrackedMapPropertySource {name='Config resource 'class path resource [application.yml]' via location 'optional:classpath:/''}, MapPropertySource {name='spring.integration.poller'}, MapPropertySource {name='springCloudBusDefaultProperties'}, OriginTrackedMapPropertySource {name='Config resource 'class path resource [bootstrap.yml]' via location 'optional:classpath:/''}, MapPropertySource {name='springCloudDefaultProperties'}, {name='Management Server'}]}
propertySources
[MapPropertySource {name='server.ports'}, BootstrapPropertySource {name='bootstrapProperties-configClient'}, BootstrapPropertySource {name='bootstrapProperties-file:///C:\\Users\\ydj90\\Downloads\\git/file:C:\Users\ydj90\Downloads\git\ecommerce.yml'}, ConfigurationPropertySourcesPropertySource {name='configurationProperties'}, MapPropertySource {name='springCloudBusOverridesProperties'}, MapPropertySource {name='gateway-properties'}, PropertiesPropertySource {name='systemProperties'}, OriginAwareSystemEnvironmentPropertySource {name='systemEnvironment'}, RandomValuePropertySource {name='random'}, CachedRandomPropertySource {name='cachedrandom'}, MapPropertySource {name='springCloudClientHostInfo'}, OriginTrackedMapPropertySource {name='Config resource 'class path resource [application.yml]' via location 'optional:classpath:/''}, MapPropertySource {name='spring.integration.poller'}, MapPropertySource {name='springCloudBusDefaultProperties'}, OriginTrackedMapPropertySource {name='Config resource 'class path resource [bootstrap.yml]' via location 'optional:classpath:/''}, MapPropertySource {name='springCloudDefaultProperties'}, {name='Management Server'}]
user-service.yml
spring:
datasource:
url: jdbc:h2:mem:testdb
driver-class-name: org.h2.Driver
generate-unique-name: false
username: '{cipher}AQBZT1bZyyKdYnWBMbh5LSjRUV+5wt50pt9WClGg+hSu7ARkvke3ndRUX0zhI8GOCfn/bJUMS1wXKz/XjpPlILkarebYyMi7iE6czM0cNC3cj1ZsH2lyk2NVcfuWutAIUCxJutsPw4zx079JJ/Alg81ycnHewmBMWofVIfcn+RWkCwkANQkv/xljQUL2w9xLgFnpBAv2tL3fjwgfQBPFbJhg/711JYmZyP0vWIISlWhyj/IebG7DcJGA0HdTu2RMdiY7oy1sez7MyyOWue8AuwGF8ll6j4qNG/1bapmooF+c/O8SYSp4fV3IgBF1q9LHgsszl9dRfqlFiUYI/q0zHViG97gamN39Qm1/B8H9eyfz+KtWrgWQnLrlXCEsAxdg/8M='
token:
expiration_time: 864000000
secret: '{cipher}AQCwCy3C26G+3di+9nxOgu2Dvb0jKOagWvPFRcsoeL5wGwId5zdxovCE/UOmMzxfm0oTmzLBr2j9I1gJvZtMtZ27lwgHlRjnZKai0bxrP9QEk5Uvwxb7mzzIYwnyRjCynIPNmxO399rZNMnb7WtTLz61lj9Nc8e4ijUgA4HfT1n+No6pIYBX2HdO3DLFPHQmCedusFCwJ4QsFVHfV/XRnnE6+AM6Sfjh6+8t1N2UxNZYPygUr2aueY1tTaHgZ1iz4uh6zT0X74fdwOCcDNIfBWwTcDpQChP3KEtfqK8XpWr6uf4r4/47ZShThPAS4ZvwCqtQmfnTL8kpH5AA2G8DgEPyVSZy8eU4oJWc83ebv/Nrbr+CMhe513/OcQpMli1D2Y4='
gateway:
ip: 172.30.1.33
order_service:
url: http://order-service/order-service/%s/orders
exception:
order_is_empty: User's orders is empty
user-service => bootstrap.yml
spring:
cloud:
config:
uri: http://localhost:8888
name: user-service
# profiles:
# active: dev
ecommerce.yml
token:
expiration_time: 864000000
secret: '{cipher}AQCwCy3C26G+3di+9nxOgu2Dvb0jKOagWvPFRcsoeL5wGwId5zdxovCE/UOmMzxfm0oTmzLBr2j9I1gJvZtMtZ27lwgHlRjnZKai0bxrP9QEk5Uvwxb7mzzIYwnyRjCynIPNmxO399rZNMnb7WtTLz61lj9Nc8e4ijUgA4HfT1n+No6pIYBX2HdO3DLFPHQmCedusFCwJ4QsFVHfV/XRnnE6+AM6Sfjh6+8t1N2UxNZYPygUr2aueY1tTaHgZ1iz4uh6zT0X74fdwOCcDNIfBWwTcDpQChP3KEtfqK8XpWr6uf4r4/47ZShThPAS4ZvwCqtQmfnTL8kpH5AA2G8DgEPyVSZy8eU4oJWc83ebv/Nrbr+CMhe513/OcQpMli1D2Y4='
gateway:
ip: 172.30.1.33
apigateway-service => bootstrap.yml
spring:
cloud:
config:
uri: http://localhost:8888
name: ecommerce
0
안녕하세요, 이도원입니다.
Debugging을 통해 올려 주신 코드에서, 사용된 env.getProperty("token.secret")의 값을 확인해 보시 ㄹ수 있을 까요? 말씀하신 것처럼 Response header에 있는 토큰 값으로 Jwts.parser()를 진행하는 데, Invalid token이라는 오류가 발생하는 것으로 봐서는 잘못된 secret, body(토큰 내용), expiration_time 등이 오류인지라 디버깅을 통해 지정하신 설정값으로 실행되는 것인지 확인해 봐야 할 것 같습니다.
subject = Jwts.parser().setSigningKey(env.getProperty("token.secret"))
.parseClaimsJws(jwt).getBody()
.getSubject();
실행하고 있는 yml 파일 및 해당 애플리케이션의 콘솔로그(초반)도 같이 공유해 주시면, 어떤 설정 파일이 사용중인지 같이 확인해 보도록 하겠습니다.
감사합니다.