401 Unauthorized error with Jawbone Up API and Ruby on Rails -


i trying access jawbone api via omniauth, httparty & ruby on rails. i'm passing header authorization => bearer: [token_here] required api docs, it's still giving me 401 error , can't life of me figure out why. i'm able token via omniauth , store session[:token], api returns 401 unauthorized.

api documentation: https://jawbone.com/up/developer/authentication

i've searched stack overflow , couldn't find solution this. what's problem?

my code is:

sessions_controller.rb

def create auth_hash = request.env['omniauth.auth']  if session[:user_id]     #if there's session, create authorization     user.find(session[:user_id]).add_provider(auth_hash)  else      auth = authorization.find_or_create(auth_hash)     session[:user_id] = auth.user.id     session[:token] = auth.user.authorizations.first.token   end redirect_to '/today' end 

data_processor.rb

class dataprocessorcontroller < applicationcontroller   def today     @current_user_dp = session[:user_id]     @token_dp = session[:token]     @authorization_dp = "bearer " + @token_dp     #@auth = "bearer " + session[:current_user].authorizations.first.token unless session[:user_id].nil?     @result = httparty.get('http://jawbone.com/nudge/api/v.1.1/users/@me/goals',                            :headers => { "authorization" => @authorization_dp, "accept" => "application/json"}) unless session[:token].nil?    end end 

results.html.erb

<p>result: <%= @result %></p> <p>auth header: <%= @result.request.inspect%></p> 

output of html file:

result: {"meta"=>{"code"=>401, "error_detail"=>"you must logged in perform action", "error_type"=>"authentication_error", "message"=>"unauthorized"}, "data"=>{}}  auth header: #<httparty::request:0x007fe446bb3320 @http_method=net::http::get, @path=#<uri::https:0x007fe446bbb408 url:https://jawbone.com/nudge/api/v.1.1/users/@me/goals>, @options={:limit=>4, :default_params=>{}, :follow_redirects=>true, :parser=>httparty::parser, :connection_adapter=>httparty::connectionadapter, :headers=>{"authorization"=>"bearer xxxxxxxxxtoken_herexxxxxxxxxxxxx", "accept"=>"application/json"}}, @last_uri=#<uri::https:0x007fe446bba918 url:https://jawbone.com/nudge/api/v.1.1/users/@me/goals>, @raw_request=#<net::http::get get>, @last_response=#<net::httpunauthorized 401 unauthorized readbody=true>, @redirect=true> 

did solve this?

if @ other error fields may give more information. in case getting 'unauthorized scope'. requesting items in scope hadn't included in original oauth request token providing had limited scope.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -