我正在使用Oltu作为Oauth2.
使用@Context HttpServletRequest请求时,我无法检索发布数据
当我使用@FormParam时,我能够检索发布数据.
在将请求传递给OAuthTokenRequest时
OAuthTokenRequest oauthRequest = new OAuthTokenRequest(request);
Run Code Online (Sandbox Code Playgroud)
我收到了以下错误
{"error":"invalid_request","error_description":"缺少grant_type参数值"}
在oltu OAuthTokenRequest类上进行调试时,使用以下代码来检索param值
public String getParam(String name) {
return this.request.getParameter(name); // from request it is unable to get post data.As i am getting request object using @Context HttpServletRequest request .
}
Run Code Online (Sandbox Code Playgroud)
据说使用@Context HttpServletRequest请求无法获取使用@Context HttpServletRequest请求的帖子数据所以,我的问题是
如何在jax-ws中获取带有post数据的HttpServletRequest请求,以便我可以将HttpServletRequest请求传递给OAuthTokenRequest 这是我的代码
@Path("/token")
public class TokenEndpoint {
@POST
@Consumes("application/x-www-form-urlencoded")
@Produces("application/json")
public Response authorize(@FormParam("state") String state,@Context HttpServletRequest request) throws OAuthSystemException {
try {
// here I am unable to get value of request.getParameter("state")
// but using …Run Code Online (Sandbox Code Playgroud) 我有一项任务是使用Apache Oltu将OAuth 2.0协议集成到API上.由于我无法理解http://oltu.apache.org/index.html网站上的例子,有人有这方面的经验,他能否给我提示/教程我该如何实现呢?
谢谢!
我正在使用Apache的Oltu库,我正在尝试使用OAuth2通过Google进行身份验证.这是相关的代码:
OAuthAuthzResponse oar = OAuthAuthzResponse.oauthCodeAuthzResponse(request);
OAuthClientRequest clientReq = OAuthClientRequest
.tokenProvider(OAuthProviderType.GOOGLE)
.setClientId("<my-client-id>")
.setClientSecret("<my-client-secret>")
.setRedirectURI("https://test.example.com/oauthtest/oauth/google/auth")
.setCode(oar.getCode())
.setGrantType(GrantType.AUTHORIZATION_CODE)
.buildQueryMessage();
OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
// This call fails with the OAuthProblemException
OAuthAccessTokenResponse oAuthResponse = oAuthClient.accessToken(clientReq,
OAuthJSONAccessTokenResponse.class);
Run Code Online (Sandbox Code Playgroud)
我可以通过Facebook进行身份验证而不会出现问题,但无论出于何种原因,这都是失败的.我可以毫无问题地从OAuthAuthzResponse获取代码,因此我知道原始呼叫正在运行,但此后续呼叫失败.
编辑:我已经放弃使用Oltu并坚持使用HttpClient库并手动执行OAuth舞蹈的简单方法.它对我来说效果更好,我会推荐给任何想要可靠地对多个OAuth提供商进行身份验证的人.只有Twitter要求我使用Scribe.
我期待开发Spring MVC + Apache Oltu + Linkedin集成示例.在此示例中,您需要发送客户端ID和客户端密钥以从站点中的链接访问私有资源.
第一步 - 我们需要在Linkedin中创建App,请按照以下步骤操作:http://codeboxr.com/how-to-create-linkedin-app.html
创建应用程序后,您需要确保为重定向URL指定了值.
在java代码中我使用了setScope("r_network w_share r_basicprofile")setState("987654321")
当我使用以下代码时:
request= new OAuthBearerClientRequest("https://api.linkedin.com/v1/people/").buildQueryMessage();
Run Code Online (Sandbox Code Playgroud)
我得到以下错误.有人可以吗?
Could not access resource: 401 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<error>
<status>401</status>
<timestamp>1429554559432</timestamp>
<request-id>QJWNLL5PWX</request-id>
<error-code>0</error-code>
<message>Unknown authentication scheme</message>
</error>
Run Code Online (Sandbox Code Playgroud)
重要的是,我在下面得到了正确的详细信息,但似乎访问私人资源:
{"access_token":"SQXZVmVM05AOzDB_DdBm5iaJkrEC8oK-FgE1m1snEZbMcKUODew9I0ZQ6NWc8JtGDxTtEd-yyPul0FtF3-hG4ah6LZ9P4oaSVuhhtybRFmjfsZcJwOs5Lm2IDUGQnjmq5EdT3PVR7Bocq31VBXg0JtkQdImab945oicO_w2j6CjlByp-bWw",
"expires_in":5108376}
Run Code Online (Sandbox Code Playgroud) 我正在使用Apache Oltu框架实现OAuth 2.0提供程序服务器,寻找有关如何在java中生成访问令牌和秘密令牌的一些想法.请指教.
正如标题所述,我想从本机Java桌面应用程序访问bitbucket API.Bitbucket要求应用程序使用OAuth2,为此我发现Oltu应该完成这项工作.
但是,我对OAuth的了解非常有限,所以我很早就陷入了困境.这是我到目前为止所做的:
第1步:我使用我的Bitbucket帐户注册了OAuth Consumer,其中包含以下详细信息:
Name: jerseytestapp
Description:
CallbackURL: http://localhost:8080/
URL:
Run Code Online (Sandbox Code Playgroud)
问题1:我可以自动执行此步骤吗?
第2步:我运行以下Java代码:
package jerseytest;
import org.apache.oltu.oauth2.client.request.OAuthClientRequest;
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
public class BitbucketJersey {
public static void main(String[] args) {
OAuthClientRequest request;
try {
request = OAuthClientRequest
.authorizationLocation("https://bitbucket.org/site/oauth2/authorize")
.setClientId("jerseytestapp")
.setRedirectURI("http://localhost:8080")
.buildQueryMessage();
System.out.println(request.getLocationUri());
} catch (OAuthSystemException e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
第3步:我收到了以下locationURI并在Firefox中打开
https://bitbucket.org/site/oauth2/authorize?redirect_uri=http%3A%2F%2Flocalhost%3A8080&client_id=jerseytestapp
Run Code Online (Sandbox Code Playgroud)
问题2:我是否需要使用浏览器或者是否可以从java应用程序执行此操作?
我在Firefox中收到以下答案消息:
Invalid client_id
This integration is misconfigured. Contact the vendor for assistance.
Run Code Online (Sandbox Code Playgroud)
问题3:正确的后续步骤是什么,以及我的方法有什么问题?
我无法弄清楚Apache OLTU(http://oltu.apache.org/ - Java OAuth 2实现)是否已准备好生产."下载"页面上的分发文件目前都以*-0.22-incubating.zip结尾.有没有人在生产环境中有过Jersey 2.4.1 + Apache OLTU 0.22的经验?是否更好地使用已经与Jersey一起提供的OAuth 1实施并等到OAuth 2也已实施?
oltu ×7
oauth-2.0 ×5
java ×4
access-token ×1
apache ×1
google-oauth ×1
jax-ws ×1
jersey ×1
linkedin ×1
oauth ×1
spring-mvc ×1