2009-11-20 4 views
1

다소 희미한 지침을 제공 한 클라이언트와 협력하고 있습니다. 이와 URL의 형태로되어푯말이있는 OAuts - 액세스 토큰을 얻기 위해 POST에 서명하는 방법

String requestToken = provider.retrieveRequestToken 
(OAuth.OUT_OF_BAND); 

: 여기에 내가이 일에서 응답 토큰을 얻을 수있어

  1. (CommonsHttpOAuthConsumer 로 소비자와 공급자로 DefaultOAuthProvider 사용)하고있어 무엇 그래서 예를 들어 밖으로 실제 토큰 분석하고 있습니다 PARAMS : 이제 https://foobar.com/oauth/login_authorize?oauth_token=XRFCGPbES3M2bYZy...

  2. 를 - 내가 얻을 지침 말 : Given the request token obtained in step 1, login with the user’s credentials (name and password) as POST parameters and sign the request with the request token/secret POST https://foobar.com/oauth/login_authorize

이것이 제가 어려움을 느끼고있는 곳입니다. 그것은 작동하지 않습니다

consumer.setTokenWithSecret(requestToken, SECRET); 
consumer.sign(post); 

: 물론 나는이 작업을 수행 할 수 있도록 이 (post 사용자 자격 증명을 HttpPost 포함되는) 곳 requestToken 것을 입력해야합니다. 그것은 실제로 200 상태를 생성하지만 내가 얻는 것은 일반 오류 메시지입니다.

답변

0

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가와

희망 위에서 언급 한 코드이 당신에게 // 조나스

도움 않는 스크립트에서 인증을 수행 할 수 있습니다