【发布时间】:2016-07-13 16:20:30
【问题描述】:
我已经设置了一个消费者应用程序,并且大多数 oauth 工作流程看起来都是正确的,但是由于某种原因,在提供者调用回调 url 之后,它会尝试两次获取访问令牌。第一次成功
http://localhost:8080/app/ws/oauth/token [OAuth的oauth_consumer_key = “itd79n64zlwv5hhv”,oauth_nonce = “cac26978-c36c-4a8b-8f3e-3e779ff927ab”,oauth_signature = “5c8BM9qQoijXC2f5IXpQGtSQsys%3D”,oauth_signature_method = “HMAC-SHA1”,oauth_timestamp = “1458938403”,组oauth_token =“5451cf20-7eed -4797-819c-ee2316981654", oauth_verifier="c56de555-79df-455e-ab87-f5f11b953fef", oauth_version="1.0"]
响应为 200,payload 包括 oauth_token=a95d6305-4261-4c1d-a9b0-43411a0c2f2c&oauth_token_secret=573702d2-70ca-412c-84e5-868e9ee07169
然后,它再次调用该 URL。
http://localhost:8080/app/ws/oauth/token [OAuth的oauth_consumer_key = “itd79n64zlwv5hhv”,oauth_nonce = “6c013ef9-2f3c-49dd-84fb-97db73b5fb39”,oauth_signature = “5RTQE5XtcqUwEFVvYQjExhH1eio%3D”,oauth_signature_method = “HMAC-SHA1”,oauth_timestamp = “1458938403”,组oauth_token =“5451cf20-7eed -4797-819c-ee2316981654", oauth_verifier="c56de555-79df-455e-ab87-f5f11b953fef", oauth_version="1.0"
由于请求令牌已被删除且访问令牌已发出,因此导致服务器出现异常。
单步执行代码时,我可以看到 OAuthConsumerContextFilter 在第一次调用后很好地存储了访问令牌。
过滤器链以某种方式结束,并使用请求令牌将其带回 CoreOAuthConsumerSupport 中的 readResource。
我使用 spring-boot 构建了消费者应用程序。
来自:applicationContext.xml
<bean id="oscarService" class="com.mdumontier.oscar.labline.service.OscarService">
<property name="oscarRestTemplate">
<bean class="org.springframework.security.oauth.consumer.client.OAuthRestTemplate">
<constructor-arg ref="oscar" />
</bean>
</property>
</bean>
<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user name="marissa" password="wombat" authorities="ROLE_USER" />
<security:user name="sam" password="kangaroo" authorities="ROLE_USER" />
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>
<security:http auto-config='true' >
</security:http>
<oauth:consumer resource-details-service-ref="resourceDetails" oauth-failure-page="/oauth_error.jsp">
<oauth:url pattern="/oscar/**" resources="oscar"/>
</oauth:consumer>
<oauth:resource-details-service id="resourceDetails">
<oauth:resource id="oscar"
key="itd79n64zlwv5hhv"
secret="d3psvmrn8k1xws9x"
request-token-url="http://localhost:8080/app/ws/oauth/initiate"
user-authorization-url="http://localhost:8080/app/ws/oauth/authorize"
access-token-url="http://localhost:8080/app/ws/oauth/token"/>
</oauth:resource-details-service>
【问题讨论】:
标签: oauth spring-security