Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8183621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:13:07+00:00 2026-06-07T01:13:07+00:00

I am trying to setup json based authentication on my current rails app. The

  • 0

I am trying to setup json based authentication on my current rails app. The app’s authentication is currently handled by devise.

I have read couple of questions on stackoverflow, but I do not seem to get it working.

routes.rb:

devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks", :sessions => 'users/sessions' }

SessionsController:

class Users:: SessionsController < Devise::SessionsController
  def create
    resource = warden.authenticate!(:scope => resource_name, :recall => :failure)
    return sign_in_and_redirect(resource_name, resource)
  end

  def sign_in_and_redirect(resource_or_scope, resource=nil)
    scope = Devise::Mapping.find_scope!(resource_or_scope)
    resource ||= resource_or_scope
    sign_in(scope, resource) unless warden.user(scope) == resource
    return render :json => {:success => true, :redirect => stored_location_for(scope) || after_sign_in_path_for(resource)}
  end

  def failure
    return render:json => {:success => false, :errors => ["Login failed."]}
  end
end

Not sure where I have gone wrong. The call I am making is:

JSON:

Content-Type: application/json
Accept: application/json
data: {user: {password: mypass, email: some_email@gmail.com}}

The Error:

MultiJson::DecodeError (756: unexpected token at '{user: {password: mypass, email:    some_email@gmail.com}}'):
2012-06-30T18:10:10+00:00 app[web.1]:   vendor/bundle/ruby/1.9.1/gems/json-1.6.5/lib/json/common.rb:148:in `parse'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T01:13:11+00:00Added an answer on June 7, 2026 at 1:13 am

    If you paste that JSON into http://jsonlint.com, you get the same error.. Instead, you should wrap your values in quotes:

    {
        "user": {
            "password": "mypass",
            "email": "some_email@gmail.com"
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My setup: Rails 2.3.10, Ruby 1.8.7 I have experimented, without success, with trying to
I am trying to build a rails API for an iphone app. Devise works
Hi all i am trying to setup a json feed. i have been working
I'm trying to setup a subdirectory in my Rails 3.2.3 app to service API
Trying to setup a CodeIgniter based project for local development (LAMP stack), and once
I have been trying to setup git for our web development team unsuccessfully. Some
I am trying to setup SSL for my heroku app. I am using the
I'm trying to setup Ember.js with Rails 3.1 and I'm getting the following error
I have this setup: class UsersController < InheritedResources::Base respond_to :html, :js, :xml, :json def
I am trying to setup a Spring Integration based Restful service. I am trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.