我如何在grape API中实现authenticate_or_request_with_http_token。下面是我的代码:
module Articles
class ArticleData < Grape::API
include ActionController::HttpAuthentication::Token::ControllerMethods
# http_basic do |email, password|
# user = User.find_by_email(email)
# user && user.valid_password?(password)
# end
before do
error!("401 Unauthorized", 401) unless authenticated
end
helpers do
def authenticated
authenticate_or_request_with_http_token do |token, options|
apiKey = ApiKey.where(auth_token: token).first
#ApiKey.exists?(access_token: token)
end
end
end
resource :article_data do
desc "Return all article data"
get do
Article.all
end
desc "create a new article"
## This takes care of parameter validation
params do
requires :title, type: String …Run Code Online (Sandbox Code Playgroud) 我怎么能POST JSON参数AFNetworking?以下是示例JSON格式.先感谢您.
{
"application": {
"identifier": "appDev"
},
"sso": {
"version": 2.0,
"session_expiry": 43200
},
"user": {
"password": "xxxx~!@",
"username": "xxx0min"
},
"coordinate": {
"latitude": 10.9948629,
"longitude": -169.5213749
}
}
Run Code Online (Sandbox Code Playgroud)
我成功创建了一个JSON:
NSDictionary *parameters = @{@"application": @{@"identifier": @"appDev"}, @"sso": @{@"version": @"2.0", @"session_expiry":@43200}, @"user": @{@"password":@"xxxx~!@", @"username":@"xxx0min"}, @"coordinate": @{@"latitude":@10.9948629, @"longitude":@-169.5213749}};
Run Code Online (Sandbox Code Playgroud)