signature=7db5437b326fdc6e2b4c8035139002f8,openid - Signed JWT rejected: Invalid signature

该博客内容描述了一个单元测试用例,其中尝试使用NimbusJwtDecoder解码两个JWT(访问令牌和身份ID令牌)。在解码访问令牌时遇到问题,抛出了一个`JwtException`,详细错误信息指出签名无效。测试用例在`test()`方法中解码访问令牌失败,在`test1()`方法中解码身份ID令牌成功。
摘要由CSDN通过智能技术生成

Hi Folks, here is how to reproduce:

This UT, has two signatures... test() .. the access token fails ... test1() ... the id token passes (or did when I ran the test :)

The issues is repeatable. Same happens if you post into https://jwt.io/ debugger.

Steve

package com.kloudspot.licensing;

import org.junit.jupiter.api.Test;

import org.springframework.security.oauth2.jwt.Jwt;

import org.springframework.security.oauth2.jwt.NimbusJwtDecoder;

import org.springframework.security.oauth2.jwt.NimbusJwtDecoder.JwkSetUriJwtDecoderBuilder;

public class JwtTest {

static String sampleAccess = "eyJ0eXAiOiJKV1QiLCJub25jZSI6ImZGLWpjTTkxejQ0MG9VVjJucnE0cUx5bjhVU3NITk9wT29RZ1pXbUZhcjQiLCJhbGciOiJSUzI1NiIsIng1dCI6IllNRUxIVDBndmIwbXhvU0RvWWZvbWpxZmpZVSIsImtpZCI6IllNRUxIVDBndmIwbXhvU0RvWWZvbWpxZmpZVSJ9.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTAwMDAtYzAwMC0wMDAwMDAwMDAwMDAiLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC8zMTJkMzM5Yi1iY2U1LTRiMzItOGNkZS1iY2I2N2UzZDgzNDQvIiwiaWF0IjoxNTg1MTU2MjQyLCJuYmYiOjE1ODUxNTYyNDIsImV4cCI6MTU4NTE2MDE0MiwiYWNjdCI6MCwiYWNyIjoiMSIsImFpbyI6IkFXUUFtLzhQQUFBQU5iNllIMzNPd0FzalFxVEJqbzNhYkFIbC8yWFA0STdVYTdmZVlMeVlCSHpmbTNzSmV2S0Rhbk8xWWppQjZUdzN6SzIrMjZEaVRaVU9KUkdIaX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JpZHAiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC8yODFkZTg1OS1jNzJhLTRiNTgtOGVmMy00MzBkMDBkZDVmNDMvIiwibmFtZSI6InN0ZXZlQGtsb3Vkc3BvdC5jb20iLCJub25jZSI6Ik9XNXlNblJyVVhkMmMwTk5ZekZNYXpCU0xYUlpUVTlaWWt4M1ZWOS1UMFk0TFd0QlgyaFpNVzlSYm5wSyIsIm9pZCI6ImZiMDA4NGMzLWI3NjYtNDczMy04MzgzLTJjMmM3YzFlYWIyMiIsInByZWZlcnJlZF91c2VybmFtZSI6InN0ZXZlQGtsb3Vkc3BvdC5jb20iLCJzdWIiOiJDejlhRXNLeWhEQjNBNThwWEJGckF4LXdGTmlMUVQ5R3dkazhQOXlrU1lzIiwidGlkIjoiMzEyZDMzOWItYmNlNS00YjMyLThjZGUtYmNiNjdlM2Q4MzQ0IiwidXRpIjoiWnVybHFZdDJERTZSMXJPX3ZfcUlBQSIsInZlciI6IjIuMCJ9.R3RGx6u_Ojt4b6AWmGagSd3eJH36sVgEGcBg133pYr_JFHP4TPbEeAMQc99PaiYJD145Hp9zKEty68TrXidZkAWb6TIttwUroecQjoSCE9S8tFxreVX8X-pqx4fWoepJKNr2DYmFzzji1-uXqmdsW_l5qDNeElJiL3rRCnUPsu1ICnNDXyDkIQVjBmsopwn0RHNdQ_uiteJLIoGTuR4Pi9mvJ1-B1Pu8cEp7yMJTJGA0iPEENDs_v6rVzyumG9rzTVzqVL2hN_aXV8eZUWaHpb8fJPrHJxgLpbVAZfsu5N1M8ihpyiU_1ZUu6n5ii9PrsD0MYgIRUZFIGp10W7ecxw" ;

@Test

public void test() {

JwkSetUriJwtDecoderBuilder tt = NimbusJwtDecoder.withJwkSetUri("https://login.microsoftonline.com/organizations/discovery/v2.0/keys");

NimbusJwtDecoder aa = tt.build();

Jwt jj = aa.decode(sampleAccess);

}

@Test

public void test1() {

JwkSetUriJwtDecoderBuilder tt = NimbusJwtDecoder.withJwkSetUri("https://login.microsoftonline.com/organizations/discovery/v2.0/keys");

NimbusJwtDecoder aa = tt.build();

Jwt jj = aa.decode(sampleId);

}

}

The failure is:

org.springframework.security.oauth2.jwt.JwtException: An error occurred while attempting to decode the Jwt: Signed JWT rejected: Invalid signature

at org.springframework.security.oauth2.jwt.NimbusJwtDecoder.createJwt(NimbusJwtDecoder.java:159)

at org.springframework.security.oauth2.jwt.NimbusJwtDecoder.decode(NimbusJwtDecoder.java:125)

at com.kloudspot.licensing.JwtTest.test(JwtTest.java:19)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:498)

at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:675)

at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)

at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:125)

at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:132)

at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:124)

at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:74)

at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)

at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)

at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:104)

at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:62)

at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:43)

at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:35)

at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)

at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)

at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:202)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:198)

at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)

at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)

at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)

at java.util.ArrayList.forEach(ArrayList.java:1257)

at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)

at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)

at java.util.ArrayList.forEach(ArrayList.java:1257)

at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)

at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)

at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)

at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)

at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)

at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)

at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)

at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)

at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)

at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)

at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)

at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:137)

at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:89)

at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)

at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)

Caused by: com.nimbusds.jose.proc.BadJWSException: Signed JWT rejected: Invalid signature

at com.nimbusds.jwt.proc.DefaultJWTProcessor.(DefaultJWTProcessor.java:103)

at org.springframework.security.oauth2.jwt.NimbusJwtDecoder$JwkSetUriJwtDecoderBuilder.processor(NimbusJwtDecoder.java:283)

at org.springframework.security.oauth2.jwt.NimbusJwtDecoder$JwkSetUriJwtDecoderBuilder.build(NimbusJwtDecoder.java:298)

at com.kloudspot.licensing.JwtTest.test(JwtTest.java:17)

... 65 more

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值