2016-11-18 3 views
0

rails 응용 프로그램, 설정 포도를 사용하고 모든 끝점을 인증하려고합니다. 그래서 grape token auth https://github.com/mcordell/grape_token_auth을 시도하고 github 문서에서 설명한대로 설정하십시오. 이것들은 나의 구성입니다.포도 토큰 인증 "오류": "404 API 버전을 찾을 수 없음"

초기화/gta.rb이 폴더 구조를

app/api/tmo/api.rb -> mounted two version root file 
app/api/tmo/vl/root.rb -> mounted all the other files for v1 
app/api/tmo/vl/restaurants.rb -> here lies the mount authentication 

include GrapeTokenAuth::MountHelpers 
include GrapeTokenAuth::TokenAuthentication 
mount_registration(to: '/auth', for: :user) 
mount_sessions(to: '/auth', for: :user) 
mount_token_validation(to: '/auth', for: :user) 
mount_confirmation(to: '/auth', for: :user) 

이다 API에 대한

GrapeTokenAuth.setup! do |config| 
    config.mappings = { user: User } 
    config.secret = 'aaa' 
end 

그래서 내 경로가 같은

Running via Spring preloader in process 9309 
POST  /auth/api/v1(/.:format) 
DELETE  /auth/api/v1(/.:format) 
PUT  /auth/api/v1(/.:format) 
POST  /auth/api/v1/sign_in(.:format) 
DELETE  /auth/api/v1/sign_out(.:format) 
GET  /auth/api/v1/validate_token(.:format) 
GET  /auth/confirmation/api/v1(/.:format) 
GET  /api/v1/statuses/public_timeline(.:format) 

내가 액세스 할 때/API/V1/status/public_timeline이 401 인증을받지 못했음을 의미하므로 authenticate_user! 방법은

작업 있지만 내가 게시 할 때에/인증/API/V1 내가 얻을 오류가 발생되는 경우

{ 
    "error": "404 API Version Not Found" 
} 

는 어떻게 확인합니까 아니면 내가 이것을 어떻게 해결합니까 다음과 같은 오류?

답변

0

grape_token_auth을 설정하는 동안 정확히 동일한 문제가 발생했습니다. 나는 다음을 수행하여 해결 :이 경우

namespace :auth do 
    mount_registration(to: '/', for: :user) 
    mount_sessions(to: '/', for: :user) 
    mount_token_validation(to: '/', for: :user) 
    mount_confirmation(to: '/ ', for: :user) 
end 

, 당신은 예를 들어 v1/auth/sign_out를 호출 할 수 있으며 작동합니다. 네임 스페이스가 없으면 엔드 포인트를 직접 호출합니다 (v1/sign_out).

의도적 인 경우 확인 또는 아니 포도 API의 변화,하지만 당신은 /auth/v1/sign_out 같은 엔드 포인트를 호출해야하고 version을 제공 할 것입니다 의미 /auth에 인증 엔드 포인트의 루트 변경됩니다 to: '/auth'의 기본 설정을 사용하여이 있다면 다른 방법으로 포도에 옮겨서 그것에 대해 불평하지 마십시오.

원래에서 게시했습니다 https://github.com/mcordell/grape_token_auth/issues/52#issuecomment-277449284

관련 문제