2014-10-02 3 views
3

레일 응용 프로그램과 동일한 서버에있는 magento와 통신해야하는 레일 응용 프로그램이 있습니다. 나는 SOAP로 모든 의사 소통을 만들었지 만 그것은 정말로 느리고 모든 것을 REST로 바꾸고 싶다.rails - magento api의 토큰 요청 REST

저는 토큰을 요청하기 위해 magento에 보낼 consumer keyconsumer secret입니다.

DOCS : oauth githubmagento oauth

@consumer = OAuth::Consumer.new("44a41ac2e67b", "89578e79570738d", { request_token_path: '/oauth/initiate', access_token_path: '/oauth/token' ,site: "http://shop.myproject.com" }) 
=> #<OAuth::Consumer:0x000000093955e0 @key="44a1edf5861edf37c", @secret="f87a0e4bfb7663fb78d", @options={:signature_method=>"HMAC-SHA1", :request_token_path=>"/oauth/initiate", :authorize_path=>"/oauth/authorize", :access_token_path=>"/oauth/token", :proxy=>nil, :scheme=>:header, :http_method=>:post, :oauth_version=>"1.0", :site=>"http://shop.myproject.com"}> 

@request_token = @consumer.get_request_token 
=> Got good response and request_token is good 

From magento docs: 
User Authorization 

The second step is to request user authorization. After receiving the Request Token 
from Magento, the application provides an authorization page to the user. The only 
required parameter for this step is the Request Token (oauth_token value) received from 
the previous step. The endpoint is followed by an oauth_token parameter with the value 
set to the oauth_token value. 

@access_token = @request_token.get_access_token 
OAuth::Unauthorized: 400 Bad Request 

기본적으로 나는 액세스 토큰 클릭에 대한 사용자 교환 요청 토큰 허용하거나 사용자 이름과 암호를 입력 페이지에 있어요. 하지만 백그라운드에서 모든 것을해야하기 때문에 액세스 토큰을 요청하기 전에 어떤 단계가 필요합니다. 나는 이것을 어떻게하는지 문서화에서 찾을 수없고 PHP 배경도 없다.

이미 읽은

: 1, 2,

3 댓글 섹션의 다른 자세한 내용은 저에게 문의하십시오.

답변

3

소비자의 승인 경로를 추가하여 수정하십시오.

1 아래 불량 가이드) 만들기 소비자

@consumer = OAuth::Consumer.new("44a41ac2e67b", "89578e79570738d", { 
    request_token_path: '/oauth/initiate', 
    access_token_path: '/oauth/token', 
    authorize_path: '/admin/oauth_authorize', 
    site: "http://shop.myproject.com" 
    }) 

2) 취득

@request_token = @consumer.get_request_token 
토큰 요청) 권한을 부여 받기 URL

@authorized_url = @request_token.authorize_url 
,

4) URL

6) 액세스 토큰이기 때문에

@access_token = @request_token.get_access_token(oauth_verifier: OAUTH_VERIFIER) 

토큰 액세스 할 수 있습니다에서

5) 잡아 oauth_verifier 권한을 부여 클릭 자격 증명을 입력을 클릭 변경하지 않으려 고 YAML.dump로 직렬화하고 저장했습니다.