OAuts with Signpost-如何签署POST以获取访问令牌

OAuts with Signpost-如何签署POST以获取访问令牌,post,oauth,signpost,auth-token,Post,Oauth,Signpost,Auth Token,我和一位客户一起工作,他给了我一些模糊的信息 说明书下面是我正在做的(使用commonHttpOAuthConsumeras 消费者和DefaultOAuthProvider作为提供者) 我可以通过执行以下操作获取响应令牌: String requestToken = provider.retrieveRequestToken (OAuth.OUT_OF_BAND); 这是带有参数的URL形式,因此我正在解析实际的令牌 例如: https://foobar.com/oauth/login_au

我和一位客户一起工作,他给了我一些模糊的信息 说明书下面是我正在做的(使用
commonHttpOAuthConsumer
as 消费者和
DefaultOAuthProvider
作为提供者)

  • 我可以通过执行以下操作获取响应令牌:

    String requestToken = provider.retrieveRequestToken
    (OAuth.OUT_OF_BAND);
    
    这是带有参数的URL形式,因此我正在解析实际的令牌 例如:
    https://foobar.com/oauth/login_authorize?oauth_token=XRFCGPbES3M2bYZy...

  • 现在-我得到的说明是:
    给定在步骤1中获得的请求令牌,使用用户的
    凭据(名称和密码)作为POST参数,并在
    使用请求令牌/密码进行请求
    邮递https://foobar.com/oauth/login_authorize

  • 这就是我遇到困难的地方。显然,我必须输入这个 requestToken在某处,所以我这样做(
    post
    是包含用户凭据的HttpPost):

    它不起作用。它实际上生成了200个状态,但我得到的是一个
    一般错误消息

    retrieveRequestToken
    不返回请求令牌,它返回您需要将用户发送到的authenticationUrl,以便他们可以登录。请求令牌保存在提供程序对象中

    String authenticationUrl = provider.retrieveRequestToken( call_back_url )
    
    注意:根据oauth标准,用户使用其凭据登录提供商站点。在他们完成后,您(作为消费者)可以获得访问令牌,然后您可以访问提供商站点上的数据

    // After user has signed in
    provider.retrieveAccessToken(null)
    
    // access token is saved in provider and provider knows which consumer uses it
    // so now you can sign with your consumer and connect with the request
    URL url = new URL( protected_resources_url )
    HttpURLConnection request = (HttpURLConnection) url.openConnection();
    consumer.sign(request)
    request.connect()
    
    如果您具有用户凭据,则可以在脚本中执行授权

    // Using grails and functional-tests
    get(authenticationUrl)
    // Image the site shows a simple form with username/password and a login button
    setRedirectEnabled false
    form {
      username = "mario"
      password = "peach"
    
      click "login"
    }
    
    然后执行
    retrieveRequestToken
    和上面提到的代码

    希望这对你有帮助 //乔纳斯

    // Using grails and functional-tests
    get(authenticationUrl)
    // Image the site shows a simple form with username/password and a login button
    setRedirectEnabled false
    form {
      username = "mario"
      password = "peach"
    
      click "login"
    }