【发布时间】:2016-11-18 08:04:11
【问题描述】:
我正在使用 rails 应用程序,设置葡萄,并尝试验证所有端点。所以尝试了葡萄令牌身份验证https://github.com/mcordell/grape_token_auth 并按照 github 文档中的说明进行设置。这些是我的配置。
初始化程序/gta.rb
GrapeTokenAuth.setup! do |config|
config.mappings = { user: User }
config.secret = 'aaa'
end
对于 api,这是文件夹结构
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)
所以我的路线是这样的
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/statuses/public_timeline 时,它说 401 未授权,所以 authenticate_user!方法有效
但是当我发布到 /auth/api/v1 时,我收到以下错误
{
"error": "404 API Version Not Found"
}
如何检查错误发生的位置或如何解决?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 grape-api