2011-10-05 3 views
0

oauth2 제공자를 omniauth가 있고 이미 작성한 응용 프로그램에서 사용하지 않도록 설정하려고합니다. user.rb은 지금 예상대로 다른레일즈 3.1 devise_oauth2_providable을 가진 OAuth 제공자 "invalid_grant"

class User < ActiveRecord::Base 

    has_many :authentications 
    has_many :graphs 

    devise :database_authenticatable, 
    :registerable, 
    :recoverable, 
    :rememberable, 
    :trackable, 
    :validatable, 
    :omniauthable, 
    :token_authenticatable, 
    :oauth2_providable, 
    :oauth2_password_grantable, 
    :oauth2_refresh_token_grantable, 
    :oauth2_authorization_code_grantable 

....... 

} 

모든 것이 구현됩니다 만, 나는 모든 로컬이 실행에 연결하기 위해 OAuth2를 보석 (0.5.0)를 사용하려고 할 때 다음과 같은 오류가 점점 오전 내 고객.

내가에 결국 :

e.to_yaml 
"--- !ruby/exception:OAuth2::Error\nresponse: &70266332040280 !ruby/object:OAuth2::Response\n response: &70266332040340 !ruby/object:Faraday::Response\n env:\n  :method: :post\n  :body: ! '{\"error\":\"invalid_grant\",\"error_description\":\"invalid authorization\n  code request\"}'\n  :url: !ruby/object:Addressable::URI\n  validation_deferred: false\n  scheme: http\n  normalized_scheme: !!null \n  uri_string: !!null \n  hash: !!null \n  host: localhost\n  authority: !!null \n  normalized_host: !!null \n  port: 3000\n  normalized_port: !!null \n  path: /oauth2/token\n  normalized_path: !!null \n  query: !!null \n  normalized_query: !!null \n  :request_headers:\n  Content-Type: application/x-www-form-urlencoded\n  :parallel_manager: !!null \n  :request:\n  :proxy: !!null \n  :ssl: {}\n  :status: 400\n  :response_headers:\n  content-type: application/json\n  x-ua-compatible: IE=Edge\n  cache-control: no-cache\n  x-runtime: '0.119701'\n  content-length: '82'\n  server: WEBrick/1.3.1 (Ruby/1.9.2/2011-02-18)\n  date: Wed, 05 Oct 2011 14:40:10 GMT\n  connection: close\n  :response: *70266332040340\n on_complete_callbacks: []\n options:\n :parse: !!null \n error: !ruby/exception:OAuth2::Error\n response: *70266332040280\n code: invalid_grant\n description: invalid authorization code request\n parsed:\n error: invalid_grant\n error_description: invalid authorization code request\ncode: invalid_grant\ndescription: invalid authorization code request\n" 

나는 또한 어떤 상태, 어떤 최신 드래프트에서 (HTTP 제공되지 않도록 납니까 : : 예외를 제기

http://localhost:8080/oauth/callback?code=2ebd3d9d149b22becec37da7a8f1eb0d

// tools.ietf.org/html/draft-ietf-oauth-v2-22)는 콜백에 필요합니다. 이것이 문제가 될 수 있습니까? 내가 서버 출력에 명백한 오류를 받고 있지 않다 출력으로

는 :

이제 http://pastie.org/2644028

, 주목할만한 또 다른 한가지는 내가 몇 일어나고 SELECT하지만 모든 데이터가 삽입되는 것을 볼 결코 볼 수 있다는 것입니다 여러 테이블에, 특히이 예외가 던져지기 직전에 발생하는 authorization_codes로 이동하지 마십시오.

답변

0

나는 레일스 천재는 아니지만 GitHub 주위에있는 길을 알고 있으며 몇 사람이 포크에 커밋을하는 것을 발견했습니다.

내가 설정 https://github.com/socialcast/devise_oauth2_providable/pull/17

콜백이 좋은 것을 작동 이제 Gemfile에 내 소스로와 : 하나 개의 위치로 몇 유효 찾고 수정을 결합하여 나를 위해 잘 작동 포크를 만들기 위해 관리!

이제 토큰 만료를 중지하거나 user_id를 어떻게 든 응답에 넣는 방법을 알아 보겠습니다. 작업 작업.

1

쿼리를 살펴본 후 현재 시간이 expired_at 값을 지난 것 같습니다. 다음은이 오류를 호출하는 devise_oauth2_providable 코드는 다음과 같습니다

module Devise 
    module Strategies 
    class Oauth2AuthorizationCodeGrantTypeStrategy < Oauth2GrantTypeStrategy 
     def grant_type 
     'authorization_code' 
     end 

     def authenticate! 
     if client && code = AuthorizationCode.valid.find_by_token(params[:code]) 
      success! code.user 
     elsif !halted? 
      oauth_error! :invalid_grant, 'invalid authorization code request' 
     end 
     end 
    end 
    end 
end 

현재 시간이 AuthorizationCode의 expires_at 필드보다 크거나 같은 경우 유효 범위 여부를 확인하는 것이다.

+0

일반적으로 도움을 요청한 후 다시 한 번이 문제를 해결했습니다. 나는 포크의 전체 네트워크를 통해 가서 github에 고정하고 그것을 가지고있어! https://github.com/philsturgeon/devise_oauth2_providable이 코드의 변경 내용은 무엇입니까? 내 포크에서 고쳐지면 이걸 조사한 250 점을 주겠다! –

+0

오 코드를 변경하지 않았습니다. 방금 author_code가 만료되어 invalid_grant 오류가 호출되어'code = AuthorizationCode.valid.find_by_token (params [: code]) '쿼리가 nil을 반환하고 있음을 발견했습니다. –

+0

아하이 봐요. 그래, 나는 그곳에 언급 한대로 아무도 데이터베이스에 삽입되지 않았기 때문에 토큰이 발견되지 않았다. 나는 정확한 해결책을 더 이상 모르지만, 포크에 여러 개의 유효한 고정을 병합하는 것이 일을하는 것처럼 보였다. 감사! –