我成功生成了在ios端工作的令牌,我设置了一个heroku rails应用程序。如何在服务器端检索此令牌?
获取错误“1ms完成500内部服务器错误(ActiveRecord:0.0ms)
NoMethodError(未定义的方法[]' for nil:NilClass):
app/controllers/login_controller.rb:11:in 'log_in'
这是我的控制器代码:
class LoginController < ApplicationController
def index
end
def log_in
puts params
headers = {"X-Parse-Application-Id" => "APIKEY",
"X-Parse-REST-API-Key" => "APIKEY"}
query = {:username => params[:user][:username],
:password => params[:user][:password]}
@response = HTTParty.get('https://api.parse.com/1/login',
:query => query,
:headers => headers)
session[:session_token] = @response["sessionToken"]
session[:object_id] = @response["objectId"]
@object_id = session[:object_id]
@test = HTTParty.get("https://api.parse.com/1/classes/_User/#{@object_id}",
:headers => {"X-Parse-Application-Id" => "APIKEY",
"X-Parse-REST-API-Key" =>"APIKEY"} )
session[:stripe_acct_id] = @test["uid"]
end
def logout
logout = HTTParty.post('https://api.parse.com/1/logout',
:headers => {"X-Parse-Application-Id" => "APIKEY",
"X-Parse-REST-API-Key" => "APIKEY",
"X-Parse-Session-Token" => session[:session_token]})
reset_session
redirect_to :controller => "login"
end
def deauthorize
@object_id = session[:object_id]
HTTParty.post("https://connect.stripe.com/oauth/deauthorize",
:basic_auth => { :username => ENV['STRIPE_SECRET'] },
:query => { client_id: ENV['STRIPE_CONNECT_CLIENT_ID'],
stripe_user_id: session[:stripe_acct_id]})
end
end
答案 0 :(得分:0)
在你的控制器中添加:
protect_from_forgery: :null, only: :log_in
对于您的错误,因为您未在发布请求中发送用户对象。